简体   繁体   English

正加权有向无环图中的k边最短路径

[英]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. 我得到一个图,G =(V,E),即正加权,有向和非循环。 I am to design an algorithm that runs in O(k(m + n)) for reporting a k-edge shortest path from s to t. 我将设计一个在O(k(m + n))中运行的算法,用于报告从s到t的k边缘最短路径。 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. k边缘最短路径被定义为从s到t的具有k个边缘的路径,并且对于从s到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. 由于BFS不能单独用于查找最短路径(除非权重相等),我认为运行时间意味着使用BFS来查找具有k个边缘的路径。 What's throwing me off is the k, as I think it implies performing BFS k times. 什么让我失望的是k,因为我认为它意味着执行BFS k次。

My possible idea would be to run a BFS from the source to find all possible k-link paths. 我可能的想法是从源运行BFS以找到所有可能的k-link路径。 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. 通过跟踪沿途的水平并将每个节点的总路径权重存储到我的队列中,我可以找到所有可能的k-link路径及其权重。 Obviously, if I encounter the destination at a lower level with lower path weight, there is no k-edge shortest path by definition. 显然,如果我在较低级别遇到具有较低路径权重的目的地,则根据定义没有k边缘最短路径。 What about cases where there are paths with more than k edges that are less total weight? 如果有超过k个边的路径总重量减少的情况怎么办? It also is not O(k(m + n)). 它也不是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[i][j]是从sj的i-link最短路径,最初我们有

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 然后迭代K - 1次,每轮我们使用f[i][]计算f[i + 1][] ,这可以通过

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)) . 因此取O(k(n + m))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 直径为k &lt;| V |的连通加权有向图,找到最短路径 - connected weighted directed graph with diameter k< |V|, find the shortest path 最多使用 k 个顶点的有向加权图中的最短路径 - Shortest path in a directed weighted graph that uses at most k vertices 加权有向图中的最短路径 - Shortest path in weighted directed graph 极小程度有向无环图中的最短路径 - Shortest path in Directed Acyclic Graph with small degree 拓扑排序的加权有向非循环图上的最长路径搜索,但有效路径的最大边数 - Longest path search on a topologically sorted weighted directed acyclic graph, but with a maximum edge count for valid paths 加权有向图最短路径的最佳方法 - Weighted Directed Graph best method for shortest path 为了找到最短路径,如何在有向加权图中将一个边精确设置为零? - How to set exactly one edge to zero in directed weighted graph in order to find shortest path? Bellman Ford算法无法为有向边加权图计算最短路径 - Bellman Ford Algorithm fails to compute shortest path for a directed edge-weighted graph 具有两种成本的有向无环图中的最短路径 - Shortest Path in a Directed Acyclic Graph with two types of costs 有向非循环图中两个顶点之间的最大加权路径 - Maximum weighted path between two vertices in a directed acyclic Graph
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM