import sys import io, os input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline n = int(input()) edge = [[] for i in range(n)] for i in range(n-1): u, v = map(int, input().split()) u, v = u-1, v-1 edge[u].append(v) edge[v].append(u) s = [] s.append(0) par = [-1]*n ch = [[] for i in range(n)] order = [] while s: v = s.pop() order.append(v) for u in edge[v]: if par[v] != u: s.append(u) ch[v].append(u) par[u] = v order.reverse() #print(order) dp1 = [0]*n for v in order: if par[v] != -1: dp1[par[v]] += dp1[v] if par[v] > v: dp1[par[v]] += 1 #print(dp1) dp2 = [0]*n for v in range(n): dp2[v] = dp1[v] order.reverse() for v in order: temp = dp2[v] for u in ch[v]: if u > v: temp -= dp1[u] dp2[u] += temp+1 temp += dp1[u] else: temp -= dp1[u]+1 dp2[u] += temp temp += dp1[u]+1 print(*dp2, sep='\n')