Finished Prim's algorithm