#include #include #define fi first #define se second #define eb emplace_back using namespace std; using namespace atcoder; using ll = long long; int dfs(int v, int p, vector>& G) { int ret = 0; if (p != -1 && v < p) ++ret; for (int nv: G[v]) { if (nv == p) continue; ret += dfs(nv, v, G); } return ret; } void dfs2(int v, int p, int score, vector& ans, vector>& G) { if (p != -1) score += (v > p ? 1: -1); ans[v] = score; for (int nv: G[v]) { if (nv == p) continue; dfs2(nv, v, score, ans, G); } } int main() { int N; cin >> N; vector> G(N); for (int i = 0; i < N - 1; ++i) { int a, b; cin >> a >> b; --a; --b; G[a].eb(b); G[b].eb(a); } vector ans(N); ans[0] = dfs(0, -1, G); dfs2(0, -1, ans[0], ans, G); for (int x: ans) cout << x << endl; return 0; }