import sys sys.setrecursionlimit(10 ** 9) n = int(input()) edges = [[] for _ in range(n)] for _ in range(n - 1): a, b = map(int, input().split()) a -= 1 b -= 1 edges[a].append(b) edges[b].append(a) def dfs(pos, bpos): ret = 0 for npos in edges[pos]: if npos == bpos: continue if pos > npos: ret += 1 dfs(npos, pos) return ret tmp = dfs(0, -1) ans = [-1] * n def dfs2(pos, bpos, score): ans[pos] = score for npos in edges[pos]: if npos == bpos: continue if pos > npos: dfs2(npos, pos, score - 1) else: dfs2(npos, pos, score + 1) dfs2(0, -1, tmp) print(*ans, sep="\n")