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 - V[vi].select{|v| v[2] != 0}.map{|v| v[2]}
  ret = true
  begin
    col_s = col.sample(v_e.size)
    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 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
V.sort{|a, b| b[1].size <=> a[1].size}.each{|k, v|
  color(k)
}

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