import sys
import math

def get_array(): return list(map(int, sys.stdin.readline().strip().split()))
def read():  return int(input())
def reads(): return map(int, sys.stdin.readline().strip().split())
def input(): return sys.stdin.readline().strip() #strip() avoid reading '\n'

to = [0] * 102000
st = [0] * 102000
res = [0] * 102000
idx = [0] * 102000
#-- main --#

n = read()

for i in range(1, n):
    x, y = reads()
    to[x] += 1
    to[y] += 1
    idx[x] = i
    idx[y] = i
tot = 0
for i in range(1, n + 1):
    if to[i] == 1 and st[idx[i]] == 0:
        res[idx[i]] = tot
        st[idx[i]] = 1
        tot += 1
for i in range(1, n):
    if st[i] == 0:
        res[i]= tot
        tot += 1
for i in range(1, n):
    print(res[i], end = ' ')
        

        


