  We solve the Poincar\'e problem for plane foliations with only one dicritical
divisor. Moreover, in this case, we give an algorithm that decides whether a
foliation has a rational first integral and computes it in the affirmative
case. We also provide an algorithm to compute a rational first integral of
prefixed genus $g\neq 1$ of any type of plane foliation $\cf$. When the number
of dicritical divisors dic$(\cf)$ is larger than two, this algorithm depends on
suitable families of invariant curves. When dic$(\cf) = 2$, it proves that the
degree of the rational first integral can be bounded only in terms of $g$, the
degree of $\cf$ and the local analytic type of the dicritical singularities of
$\cf$.
