In a directed graph with non-negative edge weights I can easily find shortest path from u to v using dijkstra's. But is there any simple tweak to Dijkstra's so that I can find shortest path from u to v through a given vertex w. Or any other algorithm suggestions?
相关问题
- Finding k smallest elements in a min heap - worst-
- binary search tree path list
- High cost encryption but less cost decryption
- How to get a fixed number of evenly spaced points
- How to determine +/- sign when calculating diagona
相关文章
- Mercurial Commit Charts / Graphs [closed]
- What are the problems associated to Best First Sea
- Coin change DP solution to keep track of coins
- Algorithm for partially filling a polygonal mesh
- Robust polygon normal calculation
- Algorithm for maximizing coverage of rectangular a
- How to measure complexity of a string?
- Select unique/deduplication in SSE/AVX
Looks like finding u to w and then finding w to v, concatenating both results. Would it work?
Then u->w->v is the shortest path.
You can do it by running Dijkstra for two times, but you can also apply the Floyd-Warshall algorithm.
Find the shortest path from u to w, then the shortest path from w to v.
Using the following approach we could run the algorithm just once:
Note that running the shortest path from u to v is effectively continuing the algo's first run. Therefore, we are running the algo just once, by tracking if we visited 'v'.
This problem is NP-hard, so finding a polynomial time solution is unlikely. See this cstheory post for more details.