import sys input=sys.stdin.readline def dfs(start): ans = [0]*N stack = [start] parent = [N]*N part_num = [1]*N parent[start] = -1 while stack: v = stack[-1] marker = 0 cnt = 1 for u in edge[v]: if u == parent[v]: continue if parent[u]==N: #前半 marker = 1 parent[u] = v stack.append(u) else: #後半 ans[v] -= part_num[u]**2 part_num[v] += part_num[u] if marker==0: #後半だったら stack.pop() ans[v] += part_num[v]**2 return ans N = int(input()) edge = [[] for _ in range(N)] visited = [False]*N for _ in range(N-1): a,b = map(int, input().split()) edge[a-1].append(b-1) edge[b-1].append(a-1) ans = dfs(0) print(*ans,sep='\n')