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 = [0 for _ in range(n)] l = [INF for _ in range(n)] st = [~ src, src] par = [None for _ in range(n)] while len(st) > 0: cur = st.pop() if cur >= 0: for nxt in g[cur]: if nxt == par[cur]: continue r[nxt] = r[cur] + 1 par[nxt] = cur st.append(~ nxt) st.append(nxt) else: if l[~ cur] == INF: l[~ cur] = 0 if not par[~ cur] is None: l[par[~ cur]] = min(l[par[~ cur]], l[~ cur] + 1) for i in range(n): print(min(l[i], r[i]))