# 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, -1]
color_base = 1

loop do
  break if q.empty?

  node, edge = q.pop
  color_base = colors[edge] % ncolor + 1 if edge >= 0
  nh[node].each do |e|
    n = e[0]
    i = e[1]
    next if i == edge

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

puts ncolor
puts colors
