n = int(input()) info = [list(map(int, input().split())) for i in range(n - 1)] root = 0 graph = [[] for i in range(n)] for a, b in info: a -= 1 b -= 1 graph[a].append(b) graph[b].append(a) stack = [root] tp_sort = [root] visited = [False] * n visited[root] = True while stack: v = stack.pop() for nxt_v in graph[v]: if visited[nxt_v]: continue visited[nxt_v] = True stack.append(nxt_v) tp_sort.append(nxt_v) dp = [-1] * n dp_cnt = [0] * n while tp_sort: v = tp_sort.pop() dp_sum = 0 dp[v] = 0 for chi_v in graph[v]: if dp[chi_v] == -1: continue dp[v] += dp_sum * dp_cnt[chi_v] * 2 dp_cnt[v] += dp_cnt[chi_v] dp_sum += dp_cnt[chi_v] dp[v] += dp_sum * 2 + 1 dp_cnt[v] += 1 for val in dp: print(val)