Edge Shortest Path in Positive Weighted Directed Acyclic Graph
I am given a graph, G = (V, E), that is positive weighted, directed, and acyclic. I am to design an algorithm that runs in O(k(m + n)) for reporting a k-edge shortest path from s to t. A k-edge shortest path is defined as a path from s to t with k edges and the total weight of the path must also be minimum for all paths from s to t.
Since BFS can't be used alone to find shortest paths (unless the weights are equal), I think that the running time implies using BFS to find paths with k edges. What's throwing me off is the k, as I think it implies performing BFS k times.
My possible idea would be to run a BFS from the source to find all possible k-link paths. By keeping track of the level along the way and storing the total path weight to each node when I add it to my queue, I can find all possible k-link paths and their weights. Obviously, if I encounter the destination at a lower level with lower path weight, there is no k-edge shortest path by definition. What about cases where there are paths with more than k edges that are less total weight? It also is not O(k(m + n)). Any helpful hints would be appreciated.
Let f[i][j]
be the i-link shortest path from s
to j
, initially we have
f[1][x] = e(s, x);
Then iterate K - 1
times, each round we use f[i][]
to compute f[i + 1][]
, which can be done by
for each node v:
f[i + 1][v] = INF;
for each edge e[u][v]:
f[i + 1][v] = min(f[i + 1][v], f[i][u] + e[u][v]);
thus takes O(k(n + m))
.
上一篇: 给定顶点的所有最短路径
下一篇: 正加权有向无环图的边最短路径