N = gets.to_i
AB = readlines.map {|s| s.split.map(&:to_i) }

h = {}
AB.each do |a,b|
  h[a] ||= []
  h[a] << b
end
max = h.to_a.reverse.max_by {|k,v| v.size }
K = max[1].size + (max[0] == 1 ? 0 : 1)
puts K

a = Array.new(AB.size+1)
a[1] = 0
h.each do |k,v|
  v.each_with_index do |n,i|
    a[n] = a[k]+i+1
    a[n] -= K if a[n] > K
  end
end
a.shift(2)
puts a
