n = int(input());jaya= [0]*(n+1);l = []
for i in range(n-1):
	a,b = map(int,input().split());a -= 1;b -= 1;jaya[a] += 1;jaya[b] += 1;l.append([a,b])
m = 0;mex = n-2
for a,b in l:
	if jaya[a] == 1 or jaya[b] == 1:print(m);m+= 1
	else:print(mex);mex -= 1