n = gets.chomp.to_i
tree = []
lines = []
n.times { tree << [] }
(n - 1).times do
  a, b = gets.chomp.split(' ').map { |i| i.to_i - 1 }
  tree[a] << b
  tree[b] << a
  lines << "#{a}-#{b}"
end

colors = {}
parent_colors = {}
visited = Array.new(n, false)
color_count = 0
queue = [0]
visited[0] = true
until queue.empty?
  q = queue.pop
  color_count = [tree[q].length, color_count].max
  color = 1
  tree[q].each do |i|
    next if visited[i]
    color += 1 if parent_colors[q] == color
    colors["#{q}-#{i}"] = color
    colors["#{i}-#{q}"] = color
    parent_colors[i] = color
    visited[i] = true
    queue << i
    color += 1
  end
end
puts color_count
lines.each { |l| puts colors[l] }