#include using namespace std; #define bokusunny ios::sync_with_stdio(false), cin.tie(nullptr); struct Edge { int to; Edge(const int to) : to(to) {} }; using Graph = vector>; void solve() { int N; cin >> N; Graph G(N); for (int i = 0; i < N - 1; i++) { int a, b; cin >> a >> b; a--, b--; G[a].emplace_back(b); G[b].emplace_back(a); } vector ans(N); auto dfs1 = [&](auto dfs1, int u, int p) -> int { int res = 0; for (auto &[v] : G[u]) { if (v == p) continue; res += dfs1(dfs1, v, u) + (int)(u > v); } return res; }; ans[0] = dfs1(dfs1, 0, -1); auto dfs2 = [&](auto dfs2, int u, int p) -> void { for (auto &[v] : G[u]) { if (v == p) continue; if (v > u) { ans[v] = ans[u] + 1; } else { ans[v] = ans[u] - 1; } dfs2(dfs2, v, u); } }; dfs2(dfs2, 0, -1); for (auto &a : ans) cout << a << endl; } int main() { bokusunny; solve(); return 0; }