import sys class UnionFind: def __init__(self, node_size): self._node = node_size self.par = [i for i in range(self._node)] self.rank = [0] * self._node def find(self, ver): if self.par[ver] == ver: return ver else: self.par[ver] = self.find(self.par[ver]) return self.par[ver] def unite(self, ver1, ver2): ver1, ver2 = self.find(ver1), self.find(ver2) if ver1 == ver2: return if self.rank[ver1] < self.rank[ver2]: ver1, ver2 = ver2, ver1 self.par[ver2] = ver1 if self.rank[ver1] == self.rank[ver2]: self.rank[ver1] += 1 def same(self, ver1, ver2): return self.find(ver1) == self.find(ver2) def dfs(u, p, depth): ans[u] = depth for v in graph[u]: if v != p: dfs(v, u, depth + 1) if __name__ == '__main__': n = int(sys.stdin.readline()) G, graph = [[] for _ in range(n)], [[] for _ in range(n)] ver, ans = [0]*n, [0]*n for i in range(n-1): u, v = map(int, sys.stdin.readline().split()) if u > v: u, v = v, u G[v-1].append(u-1) ver[i+1] = i+1 uf = UnionFind(n) for i in range(n): for v in G[i]: graph[i].append(ver[uf.find(v)]) for v in G[i]: uf.unite(i, v) ver[uf.find(i)] = i dfs(n-1, -1, 1) for val in ans: sys.stdout.write("%s\n" % val)