n=gets.to_i
ab = (0...n-1).map{gets.split.map{|s|s.to_i-1}}


maxn = ab.flatten.each_with_object({}){|i,memo| memo[i]||=0;memo[i]+=1;}.map{|k,v|v}.max

tree = ab.each_with_object({}){|(a,b),memo| memo[a]||=[];memo[a]<<b  }

#p tree

tmp=[-1]
tree.each{|e,cs|
    cs.each_with_index{|c,i|tmp[c]=(tmp[e]+i+1)%maxn;}
}


print maxn,"\n"
print tmp.select{|x|x != -1}.map{|x|(x+1).to_s}.join("\n")