import sys sys.setrecursionlimit(10**7) n = int(input()) l = [[] for _ in range(n)] for _ in range(n-1): a,b = map(int,input().split()) l[a-1].append(b-1) l[b-1].append(a-1) vis = [0] * n vis[0] = 1 cnt = [0] * n def dfs(node): for nd in l[node]: if vis[nd] == 0: vis[nd] = 1 cnt[node] += dfs(nd) + (node > nd) return cnt[node] du = dfs(0) from collections import deque ans = [0] * n ans[0] = cnt[0] q = deque([[0,cnt[0]]]) vis = [0] * n vis[0] = 1 while q: node,cc = q.popleft() for nd in l[node]: if vis[nd] == 0: vis[nd] = 1 ncc = cc + (1 if node < nd else -1) ans[nd] = ncc q.append([nd,ncc]) for aa in ans: print(aa)