import sys #input = sys.stdin.readline #文字列につけてはダメ #input = sys.stdin.buffer.readline #文字列につけてはダメ #sys.setrecursionlimit(1000000) #import bisect #import itertools #import random from heapq import heapify, heappop, heappush #from collections import defaultdict #from collections import deque #import copy #import math #from functools import lru_cache #@lru_cache(maxsize=None) #MOD = pow(10,9) + 7 #MOD = 998244353 #dx = [1,0,-1,0] #dy = [0,1,0,-1] def main(): N = int(input()) G = [[] for _ in range(N)] for i in range(N-1): a,b = map(int,input().split()) a -= 1; b -= 1 G[a].append(b) G[b].append(a) ans = [-1]*N start = 0 stack = [0] par = [-1]*N while stack: v = stack.pop() for u in G[v]: if par[v] == u: continue par[u] = v #print(u,v) if u < v: start += 1 stack.append(u) ans[0] = start stack = [0] while stack: v = stack.pop() for u in G[v]: if par[v] == u: continue par[u] = v if u > v: ans[u] = ans[v] + 1 else: ans[u] = ans[v] - 1 stack.append(u) print(*ans,sep="\n") if __name__ == '__main__': main()