圖最短路徑之BellmanFord
阿新 • • 發佈:2021-08-29
貝爾曼-福特演算法,可以從給定一個圖和圖中的源頂點src,找到從src到給定圖中所有頂點的最短路徑。該圖可能包含負權重邊。相對於Dijkstra演算法的優勢是可以處理負權重邊,缺點則是複雜度高於Dijkstra 。具體演算法的詳細解析請參考https://www.geeksforgeeks.org/bellman-ford-algorithm-dp-23/,以下程式碼也是參考https://www.geeksforgeeks.org/bellman-ford-algorithm-dp-23/
package graph.bellman_ford;
import lombok.Data;
public class Graph {
private final int vertexCount;
private final int edgeCount;
private final Edge[] edge;
public Graph(int vertexCount, int edgeCount, Edge[] edge) {
this.vertexCount = vertexCount;
this.edgeCount = edgeCount;
this.edge = edge;
}