#!/usr/bin/ruby

g = Hash.new {|h,k| h[k] = [0] }
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]}
  k = [a.length, b.length].max
  (1..k).each do |c|
    next if a[c]
    next if b[c]
    a[c] = c
    b[c] = c
    v[i] = c
    break
  end
end

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