N = gets.to_i

G = []
readlines.each do |ab|
  a,b = ab.split.map {|s| s.to_i - 1 }
  G[a] ||= []
  G[a] << b
end
max = G.max_by {|a| a && a.size || 0 }.size
max += 1 if G.size != 1
puts max

C = [0]
G.each_with_index do |a,i|
  next unless a
  a.each.with_index(1) {|j,k| C[j] = (C[i] + k) % max }
end
C.pop
puts C.map {|c| c + 1 }
