implement prim alg for finding minimum spanning tree in weightened graph