import sys input=sys.stdin.readline sys.setrecursionlimit(2*10**5) N=int(input()) edge=[[] for i in range(N)] for i in range(N-1): v,w=map(int,input().split()) edge[v-1].append(w-1) edge[w-1].append(v-1) size=[0]*N ans=[0]*N def dfs(v,pv): size[v]=1 res=0 for nv in edge[v]: if nv!=pv: dfs(nv,v) size[v]+=size[nv] res-=size[nv]**2 res+=size[v]**2 ans[v]=res dfs(0,-1) for i in range(N): print(ans[i])