n = int(input()) g = [[] for i 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) diff = [0] * n root_res = 0 vis = [False] * n vis[0] = True stack = [0] while len(stack) > 0: v = stack.pop() for to in g[v]: if vis[to]: continue vis[to] = True stack.append(to) diff[to] = diff[v] + (1 if to > v else -1) if to < v: root_res += 1 for i in range(n): print(root_res + diff[i])