# cook your dish her
from collections import defaultdict
n=int(input())
d={}
d1={}
d2={}
ans={}
d=defaultdict(lambda: [],d)
d1=defaultdict(lambda: [],d1)
d2=defaultdict(lambda: [],d2)
ans=defaultdict(lambda: -1,ans)

b=[]
for i in range(n-1):
    u,v=map(int,input().split(" "))
    b.append((u,v))
    d[u].append(v)
    d2[u].append(v)
    d2[v].append(u)
    d1[v].append(u)

arr=[]
a=[0]*(n+1)
for i in range(1,n+1):
    if len(d[i])!=0:
        a[i]=1

i=1
while i<=n:
    if a[i]==0:
        arr.append(i)
    i+=1
k=0
#print(d,d1[2][0])
for i in arr:
    ans[(d1[i][0],i)]=k
    k+=1

#print(ans)


#print(start)

visited=[False]*(n+1)
for i in arr:
    visited[i]=True

for i in range(1,n+1):
    stack=[i]

    while len(stack)!=0:
        v=stack.pop()
        if not visited[v]:
            visited[v]=True
            stack_aux=[]
            for w in d[v]:
               # if not visited[w]:
                stack_aux.append(w)
            while len(stack_aux)!=0:
                if ans[(v,stack_aux[-1])]==-1:
                    ans[(v,stack_aux[-1])]=k
                    k+=1
                stack.append(stack_aux.pop())
    
for i in b:
    print(ans[i])
