import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines N = int(readline()) UV = [map(int, readline().split()) for _ in range(N-1)] graph = [[] for _ in range(N)] for u, v in UV: graph[u-1].append(v-1) graph[v-1].append(u-1) stack = [0] dfs_ord = [] par = [-1 for _ in range(N)] while stack: v = stack.pop() dfs_ord.append(v) for u in graph[v]: if u != par[v]: par[u] = v stack.append(u) sz = [1 for _ in range(N)] for v in dfs_ord[1:][::-1]: sz[par[v]] += sz[v] res = [0 for _ in range(N)] for v in range(N): res[v] = sz[v] * sz[v] for v in dfs_ord[1:]: res[par[v]] -= res[v] for r in res: print(r)