vector<int> inD;
struct Subtree {
bool exist;
int oneway, round;
};
struct Children {
bool exist;
int oneway, round;
};
Children rake(Children x, Children y) {
if (!x.exist) return y;
if (!y.exist) return x;
return Children{true, min(x.oneway + y.round, y.oneway + x.round), x.round + y.round};
}
Children add_edge(Subtree x, int, tuple<>) {
if (!x.exist) return {false, 0, 0};
return {true, x.oneway + 1, x.round + 2};
}
Subtree add_vertex(Children x, int v) {
if (x.exist) return {true, x.oneway, x.round};
return {inD[v], 0, 0};
return {false, 0, 0};
}
Children e() { return {false, 0, 0}; }
vector<vector<pair<int, tuple<>>>> to;
rerooting<tuple<>, Subtree, Children, rake, add_edge, add_vertex, e> tree(to);
tree.run();
for (auto x : tree.dpall) cout << x.oneway << '\n';