N=gets.to_i

edges=Array.new(N){Array.new}
ret=[]

(N-1).times do |i|
    a,b=gets.split.map(&:to_i)
    e=[a-1,b-1,-1]
    ret << e
    edges[e[0]] << e
    edges[e[1]] << e
end

k=0
N.times do |i|
    k=[k,edges[i].size].max
end

stack=[[[-1,0,-1],-1]]
while !stack.empty?
    e,from=stack.pop
    to= e[0]==from ? e[1] : e[0]
    nextcol=(e[2]+1)%k
    edges[to].each do |toe|
        next if toe[0]==from || toe[1]==from
        toe[2]=nextcol
        stack << [toe,to]
        nextcol=(nextcol+1)%k
    end
end

puts k
ret.each do |e|
    puts e[2]+1
end