import sys input = sys.stdin.readline def non_rec_dfs(s, G): N = len(G) stack = [] stack.append(s) par = [-1] * N depth = [-1] * N shallow = [10**18] * N sz = [1] * N depth[s] = 0 while stack: u = stack.pop() if u >= 0: stack.append(~u) for v in G[u]: if v == par[u]: continue par[v] = u depth[v] = depth[u] + 1 stack.append(v) else: u = ~u if len(G[u]) == 1 and u != 0: shallow[u] = 0 if u != 0: sz[par[u]] += sz[u] shallow[par[u]] = min(shallow[par[u]], shallow[u] + 1) return depth, shallow N = int(input()) G = [[] for i in range(N)] for i in range(N - 1): u, v = map(int, input().split()) u, v = u - 1, v - 1 G[u].append(v) G[v].append(u) ans1, ans2 = non_rec_dfs(0, G) for a, b in zip(ans1, ans2): print(min(a, b))