N = gets.to_i
ABs = readlines.map{|l| l.split.map(&:to_i)}
 
g = Array.new(N + 1){[]}
ABs.each_with_index{|(a, b), i| g[a] << [b, i]; g[b] << [a, i]}
c = 1
q, ans = [], []
g[1].each do |b, i|
  q << [1, b, c]
  ans[i] = c
  c += 1
end
unless q.empty?
  x, y, c = q.shift
  cc = 1
  g[y].each do |z, i|
    next if z == x
    cc += 1 if cc == c
    q <<  [y, z, cc]
    ans[i] = cc
    cc += 1
  end
end
puts ans.max
puts ans
