algorithm - 在图中找到从 s 到所有顶点的最短路径

标签 algorithm graph shortest-path

鉴于以下问题:

Given the directed graph G=(V,E) with the weight function W:V→R , describe an algorithm that find the shortest paths from S to all other Vertices , where the length of the path equals to the SUM of all the vertices.You need to change an existing algorithm , to make that work , so there's no need to write a new algorithm.

请注意权重函数在 Vertices 上,而不是在 Edges 上。 我在想的是更改 Bellman-Ford 算法并将 Relax 检查更改为以下内容:

1.if d[v]>d[u]+w[u]
 1.1 d[v] <<--  d[u]+w[u]
 1.2 PI[v] <<-- u

我认为这不够好,知道可能是什么问题吗?

谢谢,罗恩

最佳答案

w:V->R 成为您的权重函数。

创建一个权重函数:w':E->R 如下:w'(u,v) = w(v)

用 w' 运行 dijkstra/bellman-ford。设 d'[v] 是根据 w' 到 v 的最小路径权重。

然后如果最短路径是s->u1->u2->...->un->v,你得到:d'[v] = w'( s,u1) + w'(u1,u2) + ... + w'(un,v) [根据 dijkstra/bellman fofrd 的正确性] 因此 d'[v] = w( u1) + w(u2) + ... + w(un) + w(v) [根据 w' 的定义]。

因此,总的来说,您得到:d[v] = w(s) d'[v] 并且 d[v] 是顶点的最短路径。

关于algorithm - 在图中找到从 s 到所有顶点的最短路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8909423/

相关文章:

python - 查找 NetworkX 中所有节点对之间的所有最短路径

python - Bellman-Ford算法的python实现

c# - 在哈希冲突和字符串性能方面的最佳哈希算法

algorithm - 如何从IP地址计算子网掩码?

javascript - 给定一个多维数组,返回一个包含对 Angular 线总和的数组

c++ - STL 指针集。复制构造函数问题

algorithm - 在 O(log n) 时间内从二叉树中获取随机数

algorithm - 如何构建一个数组来呈现强连接组件中节点的关系?

python-3.x - 如何使用seaborn处理长轴标签?

Java迷宫最短路径误解