n=int(input()) e=[[] for i in range(n)] for i in range(n-1): a,b=map(int,input().split()) a-=1 b-=1 v=[0]*n r=[0]*n f=[0]*n q=[0] while len(q)>0: s=q[-1] if v[s]==0: v[s]=1 for t in e[s]: if v[t]==0: q+=[t] r[t]=r[s]+1 f[s]=1 else: q.pop() v=[0]*n l=[0]*n q=[] for i in range(n): if f[i]==0: q+=[i] v[i]=1 for s in q: for t in e[s]: if v[t]==0: v[t]=1 l[t]=l[s]+1 q+=[t] for i in range(n): print(min(r[i],l[i]))