class Node: def __init__(self, id): self.id = id self.children = [] self.parent = 0 self.r = 0 self.l = 0 N = int(input()) nodes = [None] * (N+1) for n in range(N-1): x,y = list(map(int, input().split(' '))) if nodes[x] == None: X = Node(x) nodes[x] = X nodes[x].children.append(y) if nodes[y] == None: Y = Node(y) nodes[y] = Y nodes[y].parent = x nodes[0] = Node(0) # find distance from the root parents = {} for n in range(1,N+1): node = nodes[n] if node != None: r = 0 parents[n] = [] while node.parent != 0: parents[n].append(node.parent) node = nodes[node.parent] r += 1 nodes[n].r = r # find leaves leaves = [] for n in range(1,N+1): node = nodes[n] if node != None and len(node.children) == 0: leaves.append(n) leaves.sort() # find distance from the leaf for n in range(1,N+1): node = nodes[n] if node != None: for l in range(len(leaves)): if n in parents[leaves[l]]: node.l = parents[leaves[l]].index(n) + 1 break for n in range(1,N+1): node = nodes[n] if node != None: print(min(node.r, node.l))