from functools import lru_cache from collections import deque N=int(input()) E={i:[] for i in range(1,N+1)} for _ in range(N-1): u,v=map(int,input().split()) E[u].append(v) E[v].append(u) T=[None]*(N+1) U=[False]*(N+1) D=[0]*(N+1) F=[[] for _ in range(N+1)] M={i:set() for i in range(N)} Q=deque() T[1]=0 M[0]={1} Q.append(1) while Q: v=Q.popleft() G=True for u in E[v]: if T[u]==None: Q.append(u) F[v].append(u) T[u]=1 d=D[u]=D[v]+1 M[d].add(u) G=False if G: U[v]=True def h(L): S=0 for p in L: S+=p*p T=sum(L+[1]) return T*T-S B=[0]*(N+1) for d in range(N-1,-1,-1): for u in M[d]: if F[u]: C=1 for a in F[u]: C+=B[a] B[u]=C else: B[u]=1 Z=[0]*(N+1) for d in range(N-1,-1,-1): for u in M[d]: C=[] for v in F[u]: C.append(B[v]) Z[u]=h(C) for i in range(1,N+1): print(Z[i])