from collections import deque N = int(input()) G = [[] for _ in range(N)] for _ in range(N - 1): u, v = map(lambda x: int(x) - 1, input().split()) G[u].append(v) G[v].append(u) que = deque([0]) visited = [False] * N visited[0] = True cost = [0] * N while que: node = que.popleft() nears = G[node] for near in nears: if visited[near]: continue if near < node: cost[0] += 1 visited[near] = True que.append(near) que = deque([0]) visited = [False] * N visited[0] = True while que: node = que.popleft() nears = G[node] for near in nears: if visited[near]: continue cost[near] = cost[node] if near > node: cost[near] += 1 else: cost[near] -= 1 visited[near] = True que.append(near) print(*cost, sep="\n")