t = int(input())-1
d = {}
l = []
for i in range(t):
	u,v = map(int,input().split())
	l.append([u,v])
	if u not in d:
		d[u] = 1
	else:
		d[u]+=1
	if v not in d:
		d[v] = 1
	else:
		d[v]+=1
a = []
for i in l:
	a.append(min(d[i[0]],d[i[1]]))
ans = [-1]*t
temp = 0
for i in range(t):
	if a[i] == 1:
		ans[i] = temp
		temp+=1
for i in range(t):
	if ans[i] == -1:
		ans[i] = temp
		temp+=1
print(*ans)
