简体   繁体   中英

k-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)) .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM