import sys sys.setrecursionlimit(10 ** 6) n = int(input()) G = [[] for _ in range(n)] for _ in range(n - 1): a, b = map(int, input().split()) a -= 1; b -= 1 G[a].append(b); G[b].append(a) gyaku = [0] * n def dfs(prev, now): if now == 0: gyaku[now] = 0 elif prev < now: gyaku[now] = gyaku[prev] + 1 else: gyaku[now] = gyaku[prev] for nex in G[now]: if nex != prev: dfs(now, nex) dfs(-1, 0) print(*gyaku, sep='\n')