import sys read=sys.stdin.buffer.read readline=sys.stdin.buffer.readline readlines=sys.stdin.buffer.readlines from collections import deque n=int(readline()) g=[[] for _ in range(n)] for _ in range(n-1): x, y=map(int, readline().split()) x-=1 y-=1 g[x].append(y) g[y].append(x) INF=10**9 d=[INF]*n que=deque() for x in range(n): if x==0 or len(g[x])==1: d[x]=0 que.append(x) while que: x=que.popleft() for y in g[x]: if d[y]>d[x]+1: d[y]=d[x]+1 que.append(y) for x in d: print(x)