Implement minimum spanning tree using Prim's algorithm