from typing import List, Tuple, Callable, TypeVar, Optional import sys import itertools import heapq import bisect import math from collections import deque, defaultdict from functools import lru_cache, cmp_to_key input = sys.stdin.readline if __file__ != 'prog.py': sys.setrecursionlimit(10 ** 6) def readints(): return map(int, input().split()) def readlist(): return list(readints()) def readstr(): return input()[:-1] def readlist1(): return list(map(lambda x: int(x) - 1, input().split())) N = int(input()) E = [[] for _ in range(N)] for _ in range(N - 1): u, v = readints() u -= 1 v -= 1 E[u].append(v) E[v].append(u) R = [0] * N is_leaf = [True] * N stack = [(0, -1)] while stack: v, p = stack.pop() if v < 0: v = ~v for dst in E[v]: if dst == p: continue is_leaf[v] = False else: if ~p: R[v] = R[p] + 1 stack.append((~v, p)) for dst in E[v]: if dst == p: continue stack.append((dst, v)) INF = 1 << 30 L = [INF] * N dq = deque() for i in range(N): if is_leaf[i]: L[i] = 0 dq.append(i) while dq: v = dq.popleft() for dst in E[v]: if L[dst] > L[v] + 1: L[dst] = L[v] + 1 dq.append(dst) for r, l in zip(R, L): print(min(r, l))