Make Prim algorithm work for graphs with no edges