Finding a shortest path that passes through some arbitrary sequence of nodes?

后端 未结 3 797
无人共我
无人共我 2021-02-04 04:23

In this earlier question the OP asked how to find a shortest path in a graph that goes from u to v and also passes through some node w. The accepted answer, which is quite good

3条回答
  •  南旧
    南旧 (楼主)
    2021-02-04 04:51

    You get the shortest path from one vertex to all the other in the graph by one call to Dijkstra's algorithm. Thus you only need to do a search for each unique starting vertex so repeated vertices does not make the problem any harder.

提交回复
热议问题