n=gets.to_i
l=[[]]
n.times do
  l << []
end
t=[]
(n-1).times do
  a,b=gets.split.map(&:to_i)
  l[a] << b
  l[b] << a
  t << [a,b]
end
k=0
l.each do |ll|
  k=ll.size if k<ll.size
end
puts k
h={}
c=[0,0]
s=[1]
i=0
while s!=[]
  z=[]
  s.each do |ss|
    l[ss].each do |lss|
      a,b=[ss,lss].sort
      if !h.has_key?([a,b])
        i=(i%k)+1
        i=(i%k)+1 if i==c[ss]
        h[[a,b]]=i
        c[lss]=i
        z << lss
      end
    end
  end
  s=z.dup
end
t.each do |tt|
  puts h[tt]
end
