Implement Prim's algorithm for minimum spanning tree.