n=gets.to_i
maxNumber = 1
nowNumber = 1
colors = [1]
oldA, oldB = gets.split.map(&:to_i)
(n-2).times do |count|
  newA, newB = gets.split.map(&:to_i)
  if oldA == newA
    nowNumber += 1
  elsif oldB == newA
    nowNumber += 1
  else
    maxNumber = nowNumber	if nowNumber > maxNumber
    nowNumber = 1
  end
  colors << nowNumber
  oldA = newA
  oldB = newB
end
puts colors.uniq.count
colors.map{|number| puts number }