require 'set'

N = gets.to_i
V = Hash.new{|h, k| h[k] = []}
E = Hash.new
(N - 1).times{|i|
  a, b = gets.chomp.split(" ").map(&:to_i)
  E[i] = [a, b, 0]
  V[a] << E[i]
  V[b] << E[i]
}

def color(vi)
  v_e = V[vi].select{|v| v[2] == 0}
  return if v_e.size == 0
  col = @col_ar.dup
  v_out = V[vi].select{|v| v[2] != 0}.map{|v| v[2]}
  ret = true
  begin
    col_s = col.sample(v_e.size)
    ret = (col_s & v_out).empty?
    if ret then
      idx = -1
      ret = v_e.all?{|a, b, c|
        op = (b == vi ? a : b)
        idx += 1
        !V[op].select{|v| v[2] != 0}.map{|v| v[2]}.include?(col_s[idx])
      }
    end
  end until ret

  if ret then
    v_e.each_with_index{|e, idx|
      e[2] = col_s[idx]
    }
  end
end

col_max = 0
V.each{|k, v| col_max = v.size if col_max < v.size}
@col_ar = (1..col_max).to_a

done = Set.new
q = [V.max_by{|k, v| v.size}[0]]
done.add(q[0])
while(q.size > 0) do
  v = q.shift
  color(v)
  V[v].each{|e|
    if v == e[1] then
      (q << e[0]; done.add(e[0])) if !done.include?(e[0])
    else
      (q << e[1]; done.add(e[1])) if !done.include?(e[1])
    end
  }
end

puts col_max
E.map{|k, v| puts v[2]}
