Prim-Dijkstra algorithm