n=int(input())
N=[]
X=[0]*(n+1)
for i in range(n-1):
    ch=input()
    L=[int(i)for i in ch.split()]
    a=L[0]
    b=L[1]
    N.append((a,b))
    X[a]+=1
    X[b]+=1

nb1=0
for i in range(n+1):
    if X[i]==1:
        nb1+=1
i=0
j=nb1
for k in range(n-1):
    if X[N[k][0]]==1 or X[N[k][1]]==1:
        print(i)
        i+=1
    else:
        print(j)
        j+=1