Implemented Prim's algorithm to find minimum spanning trees.