Weakly polynomial time algorithm