Prim's Algorithm for minimum spanning tree