应用Bellman-Ford算法后,如何找到从源到目的地的最短路径?

我正在尝试实现Bellman-Ford算法,以找到图中从源到目标的最短路径。以下是我正在使用的变量。

private int[] distances;    //at position "n" the distance of node "n" to the source is kept
private int[] predecessors; //at position "n" the predecessor of node "n" on the path
                               to the source is kept
private int source;         //source node
private int destination;    //destination node

所以我知道如何实现该算法,并且正确填充了distances和predescessors数组。我的问题是,获得这些信息后,如何找到从源到目的地的最短路径

我已经浏览了下面的链接,但是我不太明白。

此外,如果有帮助,我的输出之一是这样的:

distances = [0,10,12,18,15,13,29,19,30]
predecessors = [0,1,2,3,5,7]
source = 0;
destination = 8;

实际最短路径是

0-->2-->5-->7-->8,长度为30

图是

应用Bellman-Ford算法后,如何找到从源到目的地的最短路径?

How to get the actual path found by Bellman-Ford

ysw920221 回答:应用Bellman-Ford算法后,如何找到从源到目的地的最短路径?

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3078661.html

大家都在问