# 頂点0からの逆張り度をまず求める # 隣の頂点に移動し、大きい数字に移動するなら逆張り度が1増え、小さい数字であれば1減る N = int(input()) G = [[] for i in range(N)] for _ in range(N - 1): A,B = map(int,input().split()) G[A - 1].append(B - 1) G[B - 1].append(A - 1) stack = [] stack.append([0, -1]) val0 = 0 while stack: v, p = stack.pop() if p > v: val0 += 1 for child in G[v]: if child == p: continue stack.append([child, v]) ans = [-1] * N ans[0] = val0 stack = [] stack.append([0, -1]) while stack: v, p = stack.pop() for child in G[v]: if child == p: continue if child > v: ans[child] = ans[v] + 1 else: ans[child] = ans[v] - 1 stack.append([child, v]) for a in ans: print(a)