Prim's minimum spanning tree algorithm implementation