import Queue N = input() rinsetsu = [[] for i in xrange(N)] is_leaf = [True for i in xrange(N)] for _ in xrange(N-1): a, b = map(int, raw_input().split()) rinsetsu[a-1].append(b-1) rinsetsu[b-1].append(a-1) is_leaf[a-1] = False leaves = [i for i in xrange(N) if is_leaf[i]] ans = [float('inf') for i in xrange(N)] def bfs(start): visited = [False for i in xrange(N)] q = Queue.Queue() q.put((start, 0)) while not q.empty(): node, depth = q.get() if visited[node]: continue ans[node] = min(ans[node], depth) visited[node] = True for nn in rinsetsu[node]: if visited[nn]: continue q.put((nn, depth+1)) bfs(0) for leaf in leaves: bfs(leaf) for a in ans: print a