algorithm - 加权图和所有对路径

标签 algorithm shortest-path

我正在尝试通过此链接解决问题:

https://www.chegg.com/homework-help/questions-and-answers/consider-weighted-directed-graph-g-n-vertices-e-edges-weights-integers-suppose-g-contains--q12054851

(这不是作业题)

Consider a weighted directed graph G with n vertices and e edges, and the weights are integers. Suppose that G contains no negative cycles, and for every pair of vertices u and v in G, the distance from u to v falls in the range [-2d, 2d] for some positive integer d. We are going to fix a particular edge (x,y) in G, and consider what happens to the distances in G as we change the weight associated with that edge (and leave all other edge weights fixed).

Design an algorithm that takes G as input, as well as a specified edge (x,y) in G. The output of the algorithm should be an integral range of values that the weight of this edge (x,y) could take such that all of the distances in G would remain the same. Note that this range will be non-empty, as it must include the original weight of the edge (x,y). Also note that infinity may occur as an endpoint of your range (i.e. the range may not be finite). For this, you may return “∞” as an endpoint. The running time of your algorithm must be polynomial in n,e, and d (so your running time should not have any of these parameters appearing as exponents). Prove why the algorithm is correct.

我一直在思考以下几行: 由于距离在一个范围内,权重也应该在一个范围内。一种选择是我们多次运行 Djkstra。我们如何优化它?

最佳答案

是的,你可以运行 Dijkstra n 次。或者,您可以运行专为这些问题设计的 Floyd-Warshall。总体而言,它们具有相似的复杂性界限。

关于algorithm - 加权图和所有对路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36587124/

相关文章:

javascript - 检查对象数组中添加和删除了多少元素

algorithm - 为什么在 Bellman Ford 算法中需要 (node number - 1) 次迭代来找到最短路径?

java - A* 实现总是返回相同的值

algorithm - 给定一个加权图和自然数 k 如何找到从节点 s 到 t 的最便宜路径可以被 k 整除?

algorithm - 如何使空间复杂度为 O(1)

c - 如何找到多边形内沿 vector 的最长距离?

algorithm - 最优蚁群定位算法

prolog - 如何在 Prolog 中实现 Dijkstra 算法返回边列表?

c++ - A*寻路慢

python - 如何实现 "group_by"功能