#!/usr/bin/ruby

class Node
  attr_accessor :node, :vector
  def initialize(n)
    @node = n
    @vector = [0]
  end
  def unused
    @vector.find_index(nil) || @vector.size
  end
end

g = Hash.new {|h,k| h[k] = Node.new(k) }
v = []
k = 0

n = ARGF.gets.to_i
(n-1).times do |i|
  a, b = ARGF.gets.split.map(&:to_i).map{|x| g[x]}
#  $stderr.puts "#{a}, #{b}"
#  $stderr.puts "a=#{a.node}:#{a.vector}, b=#{b.node}:#{b.vector}"
  c = a.unused
  if c < b.unused
    c = b.unused
  end
#  $stderr.puts "new = #{c}"
  a.vector[c] = c
  b.vector[c] = c
  v[i] = c
  k = c if k < c
end

puts k
v.each {|c| puts c}
