#include #include #include #include #include #include #include #include #include #include #include #include using namespace std; using ll = long long; int x=0; vector ans; void dfs(vector>> &E, int from, int p){ for(auto [to, c] : E[from]){ if (p == to) continue; if (c == -1) x++; dfs(E, to, from); } } void dfs2(vector>> &E, int from, int p){ for(auto [to, c] : E[from]){ if (p == to) continue; if (c == 1) ans[to] = ans[from]+1; else ans[to] = ans[from]-1; dfs2(E, to, from); } } int main(){ int N, a, b; cin >> N; ans.resize(N); vector>> E(N); for (int i=0; i> a >> b; a--; b--; E[a].push_back({b, 1}); E[b].push_back({a, -1}); } dfs(E, 0, -1); ans[0] = x; dfs2(E, 0, -1); for (int i=0; i