The Poincaré problem, algebraic integrability and dicritical divisors