N = int(raw_input()) edge = [[] for _ in xrange(N +1)] for i in xrange(N - 1): x, y = map(int, raw_input().split()) edge[x].append(y) edge[y].append(x) queue = [1] dist = [N] * (N + 1) dist[1] = 0 for i in xrange(1, N + 1): if len(edge[i]) == 1: dist[i] = 0 queue.append(i) while len(queue) > 0: current = queue.pop() for nxt in edge[current]: if dist[nxt] > dist[current] + 1: dist[nxt] = dist[current] + 1 queue.append(nxt) for i in xrange(1, N + 1): print dist[i]