import sys input = sys.stdin.readline from collections import * N = int(input()) G = [[] for i in range(N)] for i in range(N - 1): u, v = map(int, input().split()) u, v = u - 1, v - 1 G[u].append(v) G[v].append(u) Q = deque() dist = [-1] * N Q.append(0) dist[0] = 0 for i in range(1, N): if len(G[i]) == 1: Q.append(i) dist[i] = 0 while Q: u = Q.popleft() for v in G[u]: if dist[v] != -1: continue dist[v] = dist[u] + 1 Q.append(v) for d in dist: print(d)