N = gets.to_i
$edges_idx = (N-1).times.each_with_object(Hash.new([])){|n, h| h[gets.split.map(&:to_i)] = n}
$adj = $edges_idx.keys.each_with_object(Hash.new([])){|(a, b), h| h[a] += [b]; h[b] += [a]}
root, children = $adj.max_by{|k, v| v.size}
p children.size
$colors = (1..children.size).to_a
$visited = Array.new
$ans = Array.new

def saiki(current, color)
    $visited[current] = true
    available_colors = $colors.reject{|c| c == color}
    $adj[current].reject{|pt| $visited[pt]}.each do |pt|
        col = available_colors.shift
        $ans[$edges_idx[[current, pt].sort]] = col
        saiki(pt, col)
    end
end
saiki(root, nil)

puts $ans