Correct prim algorithm.