# frozen_string_literal: true

require 'thread'

n = gets.to_i
ab = (n - 1).times.map { gets.split.map(&:to_i) }

h = Array.new(n + 1) { 0 }

nh = Array.new(n + 1) { [] }

colors = Array.new(n - 1){ 0 }

0.upto(n - 2) do |i|
  e = ab[i]
  h[e[0]] += 1
  h[e[1]] += 1
  nh[e[0]].push [e[1], i]
  nh[e[1]].push [e[0], i]
end

max = h.max
max_node = h.find_index(max)

q = Queue.new

ncolor = max
q.push max_node
color_base = 1

loop do
  break if q.empty?

  node = q.pop
  nh[node].each do |e|
    n = e[0]
    i = e[1]

    color = colors[i]
    if color.positive?
      color_base = (color + 1) % (ncolor + 1)
      next
    end

    q.push n
    colors[i] = color_base
    color_base = (color_base + 1) % (ncolor + 1)
  end
end

exit 1 if colors.any?(0)

puts ncolor
puts colors
