import sys sys.setrecursionlimit(10**6) n = int(input()) load = [[] for i in range(n)] for i in range(n-1): a,b = map(int,input().split()) a -= 1; b -= 1 load[a].append(b) load[b].append(a) s = 0 ans = [0]*n go = [(0,-1)] while go: np,bef = go.pop() for i in load[np]: if i == bef: continue go.append((i,np)) s += 1 if np > i else 0 def dfs(np,bef,s): ans[np] = s for i in load[np]: if i == bef: continue if i > np: dfs(i,np,s+1) else: dfs(i,np,s-1) return dfs(0,-1,s) print(*ans,sep='\n')