N = gets.to_i
ABs = readlines.map{|l| l.split.map(&:to_i)}

g = ABs.each_with_object(Hash.new{|h, k| h[k] = []}){|(a, b), h| h[a] << b; h[b] << a}
h = {}
(1 .. N).each do |a|
  cs = [*1 .. N] - g[a].map{|b| h[[a, b]]}.compact.sort
  g[a].each do |b|
    next unless h[[a, b]].nil?
    h[[a, b]] = h[[b, a]] = cs.shift
  end
end
puts g.values.map(&:size).max
ABs.each{|a, b| puts h[[a, b]]}