N = input() e = [[] for i in range(N)] S = [N]*N l = [] for i in range(N-1): x,y = map(int,raw_input().split()) e[x-1] += [y-1] e[y-1] += [x-1] for i in range(N): if len(e[i]) == 1: l += [(i,i)] d = 0 while l: nl = [] for b,h in l: S[h] = d nl += [(h,nxt) for nxt in e[h] if nxt != b and d+1 < S[nxt]] d += 1 l = nl for i in range(N): print S[i]