n = gets.to_i
a = []
b = []
connect_vertex = Array.new(n+1,0)
(n-1).times do |i|
  a[i], b[i] = gets.chomp.split(" ").map(&:to_i)
  connect_vertex[a[i]] += 1
  connect_vertex[b[i]] += 1
end
max = connect_vertex.max
puts max
sorting_array = Array.new(n+1).map{Array.new()}
(n-1).times do |i|
  small = big = 0
  small,big = a[i],b[i] if a[i] < b[i]
  small,big = b[i],a[i] if a[i] > b[i]
  for i in 1..max
    if !sorting_array[small].include?(i) && !sorting_array[big].include?(i)
      puts i
      sorting_array[small].push(i)
      sorting_array[big].push(i)
      break
    end
  end
end
