import sys input = sys.stdin.readline from collections import deque def bfs1(): q = deque([0]) visited = [-1]*N is_leaf = [True]*N while q: v = q.popleft() for nv in adj_list[v]: if visited[nv]==-1: visited[nv] = 1 is_leaf[v] = False q.append(nv) return is_leaf def bfs2(): q = deque([0]) dist = [-1]*N dist[0] = 0 for i in range(N): if is_leaf[i]: dist[i] = 0 q.append(i) while q: v = q.popleft() for nv in adj_list[v]: if dist[nv]==-1: dist[nv] = dist[v]+1 q.append(nv) return dist N = int(input()) adj_list = [[] for _ in range(N)] for _ in range(N-1): xi, yi = map(int, input().split()) adj_list[xi-1].append(yi-1) adj_list[yi-1].append(xi-1) is_leaf = bfs1() dist = bfs2() for d in dist: print(d)