Take a look at the Floyd-Warsall algorithm and Combine Sort Algorithm .
Given that the number of places to visit (peaks) is V, and the number of travelers is T, if you use the Floyd-Warsall algorithm, it should give you the shortest paths between pairs of peaks in your graph, with O (V ^ 3).
Then you can sort the lengths of the shortest paths in ascending order, which will work with complexity O (V log V).
Since you apply these algorithms sequentially, you still find the overall complexity of O (V ^ 3).
You will need to perform this second stage K times, where K is the ceiling (V / T), because at the first iteration you would visit T vertices, but V is greater than T, so you have a few more vertices to visit, At the next iteration delete the visited peaks from the calculation and sort the remaining distances (which you already found in the previous step), and then go to them from the new places of travelers T.
You can probably achieve a better result by choosing the smallest distance for each vertex, so the next selected vertex is the closest.
So your overall complexity will start to look like O (V ^ 3) + K x O (V log V), which I think tends to get closer to O (V ^ 3).
These are just a few ideas to get you started.
source share