import sys def input(): return sys.stdin.buffer.readline()[:-1] sys.setrecursionlimit(10**6) n = int(input()) adj = [[] for _ in range(n)] children = [[] for _ in range(n)] ans = [0 for _ in range(n)] for _ in range(n-1): u, v = map(int, input().split()) adj[u-1].append(v-1) adj[v-1].append(u-1) def dfs(x, p): for v in adj[x]: if v == p: continue dfs(v, x) s = sum(children[x]) res = 2*s+1 for i in children[x]: res += i * (s-i) if x != 0: children[p].append(s+1) ans[x] = res return dfs(0, -1) print(*ans, sep="\n")