from collections import deque n = int(input()) edges = [[] for _ in range(n + 1)] for _ in range(n - 1): x, y = [int(i) for i in input().split()] edges[x].append(y) edges[y].append(x) zero_nodes = [1] + [i for i, v in list(enumerate(edges))[2:] if len(v) == 1] node_lengths = [None] * (n + 1) checked_nodes = [False] * (n + 1) queue = deque() for z in zero_nodes: queue.append(z) checked_nodes[z] = True node_lengths[z] = 0 while True: i = queue.popleft() next_root_length = node_lengths[i] + 1 for t in edges[i]: if checked_nodes[t]: continue queue.append(t) checked_nodes[t] = True node_lengths[t] = next_root_length if len(queue) == 0: break node_lengths.pop(0) print(*node_lengths, sep='\n')