Perfect Prim Algorithm