import sys sys.setrecursionlimit(10**8) N = int(input()) G = [list() for _ in range(N)] for i in range(N-1): a, b = map(int,input().split()) a-=1;b-=1 G[a].append(b) G[b].append(a) cnt = 0 def dfs(v, p): global cnt for nex in G[v]: if nex==p: continue if nexv: res[nex] = res[v]+1 else: res[nex] = res[v]-1 dfs_ans(nex, v) dfs(0, -1) dfs_ans(0, -1) print(*res, sep='\n')