di = {} #Dictionary of int->tuple
edLi = []
n = int(input())
for _ in range(n-1):
    liStr = input().split()
    a = int(liStr[0])
    b = int(liStr[1]) 

    tempLi = []
    tempLi.append(a)
    tempLi.append(b) 
    edLi.append(tuple(tempLi)) 
    
    if(a in di):
        tup = di[a] 
        li = list(tup) 
        li.append(b) 
        tup = tuple(li) 
        di[a] = tup 
    else:
        li = []
        li.append(b)
        tup = tuple(li) 
        di[a] = tup 
    
    if(b in di):
        tup = di[b] 
        li = list(tup) 
        li.append(a) 
        tup = tuple(li) 
        di[b] = tup 
    else: 
        li = []
        li.append(a) 
        tup = tuple(li) 
        di[b] = tup 
print(di) 

leafNode1 = 1
leafNode2 = 2
flag = 0 
for i in di:
    if( len(di[i]) == 1 and flag == 0):
        leafNode1 = i
        flag = 1
        continue
    if( len(di[i]) == 1 and flag == 1):
        leafNode2 = i 
        break

print(leafNode1 , leafNode2) 
p = 2 
for i in range(0,n-1):
    if(leafNode1 in edLi[i]):
        print(0)
    elif(leafNode2 in edLi[i]):
        print(1) 
    else:
        print(p) 
        p += 1 