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 for u, v in edges: if u < v: if dp[v] > dp[u]: d1[v] += 1 else: d1[u] -= 1 d1[0] += 1 else: if dp[u] > dp[v]: d1[u] += 1 else: d1[v] -= 1 d1[0] += 1 for v in order: for p in g[v]: if dp[p] > dp[v]: d1[p] += d1[v] for i in range(n): print(d1[i])