N = input() rinsetsu = [[] for _ in xrange(N)] for i in xrange(N-1): x, y = map(int, raw_input().split()) x -= 1 y -= 1 rinsetsu[x].append(y) rinsetsu[y].append(x) ans = [float('inf') for _ in xrange(N)] def dfs(start, happa=False): stack = [(start, 0, None)] if happa: leaves = [] while len(stack) > 0: node, depth, parent = stack.pop() ans[node] = min(ans[node], depth) if happa and len(rinsetsu[node]) == 1 and parent is not None: leaves.append(node) continue for nn in rinsetsu[node]: if nn == parent: continue stack.append((nn, depth+1, node)) if happa: return leaves leaves = dfs(0, True) for leaf in leaves: dfs(leaf) for a in ans: print a