from collections import OrderedDict
def dfs(g,src,isv,d):
    if len(g[src]) == 0:
        return 1
    count = 1
    for i in g[src]:
        if i not in isv:
            isv.add(i)
            ct = dfs(g,i,isv,d)
            d[(min(src,i),max(src,i))] = ct
            count += ct
    return count
n = int(input())
g = [list() for _ in range(n+1)]
d = OrderedDict()
for _ in range(n-1):
    u,v = map(int,input().split())
    d[(min(u,v),max(u,v))] = 0
    g[u].append(v)
dfs(g,1,set(),d)
a = []
for i in d:
    a.append((d[i]*(n-d[i]),(i[0],i[1])))
a.sort()
for i in range(len(a)):
    d[a[i][1]] = i
for i in d:
    print(d[i])