import sys input = sys.stdin.readline N = int(input()) e = [[] for _ in range(N + 1)] for _ in range(N - 1): u, v = map(int, input().split()) e[u].append(v) e[v].append(u) sm = 0 dp = [0] * (N + 1) s = [1] vis = [0] * (N + 1) vis[1] = 1 while len(s): x = s.pop() for y in e[x]: if vis[y]: continue vis[y] = 1 s.append(y) dp[y] = dp[x] if x < y: dp[y] += 1 else: dp2[y] -= 1 sm += 1 dp2 = [0] * (N + 1) dp2[1] += sm s = [1] vis = [0] * (N + 1) vis[1] = 1 while len(s): x = s.pop() for y in e[x]: if vis[y]: continue vis[y] = 1 s.append(y) dp2[y] += dp2[x] for x in range(1, N + 1): print(dp[x] + dp2[x])