n = gets.to_i
g = Array.new(n+1).map{Array.new}
a = Array.new
b = Array.new

(n-1).times do |i|
  a[i],b[i]=gets.chomp.split(" ").map(&:to_i)
  g[a[i]].push([b[i],i])
  g[b[i]].push([a[i],i])
end

maxsize = 0
v = 0
n.times do |i|
  if maxsize < g[i+1].length
    maxsize = g[i+1].length
    v = i+1
  end
end

puts maxsize

color = Array.new(n-1,0)
queue = []
queue.push([a[0],0])
done = []

while !queue.empty?
  v = queue[0]
  queue.shift
  if !done.include?(v[0])
    num = 1
    g[v[0]].each do |des|
      if !done.include?(des[0])
        while num == v[1]
          num += 1
        end
        color[des[1]] = num
        queue.push([des[0],num])
        num += 1
      end
    end
    done.push(v[0])
  end
end

color.each do |x|
  puts x
end