Constructing a minimum spanning tree with the prim algorithm