n = int(input()) g = [[] for _ in range(n)] for _ in range(n - 1): u, v = map(int, input().split()) u -= 1 v -= 1 g[u].append(v) g[v].append(u) cnt = [0 for _ in range(n)] src = 0 par = [None for _ in range(n)] st = [~ src, src] while len(st) > 0: cur = st.pop() if cur >= 0: for nxt in g[cur]: if nxt == par[cur]: continue par[nxt] = cur st.append(~ nxt) st.append(nxt) else: cnt[~ cur] += 1 if not par[~ cur] is None: cnt[par[~ cur]] += cnt[~ cur] ans = [0 for _ in range(n)] for v in range(n): if not par[v] is None: ans[par[v]] -= cnt[v] ** 2 ans[v] += cnt[v] ** 2 print(*ans, sep='\n')