from collections import deque INF = 1 << 60 n = int(input()) g = [[] for _ in range(n)] for _ in range(n - 1): x, y = map(int, input().split()) x -= 1 y -= 1 g[x].append(y) g[y].append(x) src = 0 r = [INF for _ in range(n)] r[src] = 0 dq = deque([src]) while len(dq) > 0: cur = dq.popleft() for nxt in g[cur]: if r[nxt] < INF: continue r[nxt] = r[cur] + 1 dq.append(nxt) l = [INF for _ in range(n)] for v in range(n): if len(g[v]) == 1: l[v] = 0 dq.append(v) while len(dq) > 0: cur = dq.popleft() for nxt in g[cur]: if l[nxt] < INF: continue l[nxt] = l[cur] + 1 dq.append(nxt) for i in range(n): print(min(l[i], r[i]))