import math
from collections import defaultdict
n = int(input())
adj_lis = defaultdict(int)
edges = []
for i in range(n-1):
    x, y = [int(i) for i in input().split()]
    adj_lis[x] += 1
    adj_lis[y] += 1
    edges.append([x, y])
leaves = {}
for i in range(1, n+1):
    if adj_lis[i] == 1:
        leaves[i] = 1
tot_leaves = len(list(leaves.keys()))
high = tot_leaves
low = 0
for i in range(len(edges)):
    x, y = edges[i]
    if (x in leaves) or (y in leaves):
        print(low)
        low += 1
    else:
        print(high)
        high += 1
