N = gets.to_i
AB = readlines.map {|ab| ab.split.map {|s| s.to_i - 1 } }

G = []
max = 0
AB.each do |a,b|
  G[a] ||= []
  G[a] << b
  max = G[a].size if max < G[a].size
end
max += 1 if G.size != 1
puts max

C = []
G.each_with_index do |a,i|
  a && a.each.with_index(C[i] ? 1 : C[i]=0) {|j,k| C[j] = (C[i] + k) % max }
end
AB.each {|a,b| puts C[b] + 1 }
