def tree_dfs(g, root=0): s = [root] d = [1] * len(g) order = [] while s: p = s.pop() d[p] = 0 order.append(p) for node in g[p]: if d[node]: s.append(node) return order def tree_depth(g, root=0): s = [root] d = [-1] * len(g) d[root] = 0 while s: p = s.pop() for node in g[p]: if d[node] == -1: d[node] = d[p] + 1 s.append(node) return d n = int(input()) g = [[] for _ in range(n)] edges = [] for i in range(n - 1): a, b = map(int, input().split()) g[a - 1].append(b - 1) g[b - 1].append(a - 1) edges.append((a - 1, b - 1)) order = tree_dfs(g, 0) dp = tree_depth(g, 0) d1 = [0] * n d2 = [0] * n for u, v in edges: if dp[u] < dp[v]: d1[v] += 1 else: d2[u] += 1 for v in order: for p in g[v]: if dp[p] > dp[v]: d1[p] += d1[v] for v in order[::-1]: for p in g[v]: if dp[p] < dp[v]: d2[p] += d2[v] for i in range(n): print(d1[i] + d2[i])