n=int(input())
a=[ [] for i in range(n+1)]
b=[]
for _ in range(n-1):
    u,v=map(int,input().split())
    a[u].append(v)
    a[v].append(u)
    b.append((u,v))
c=0
for _ in range(1,n+1):
    
    if len(a[_])==1:
        c+=1
p=0
q=c
for i in b:
    if len(a[i[0]])==1 or len(a[i[1]])==1:
        print(p)
        p+=1
    else:
        print(q)
        q+=1
    
    