【介绍】贝尔曼福特算法(Bellman-Ford)是解决最短路径问题的经典算法之一,目标是找到从Src到每一个点的最短路径。
【代码】本视频所用伪代码如下:
BELLMAN-FORD(G, src) {
set all vertices v.key = ∞
set all vertices v.previous = ∅
src.key = 0
for i = 1 to |G.V| - 1
for each edge (u, v)
RELAX(u, v, weight(u, v))
// Check for a negative cycle
for each edge (u, v)
if v.key > u.key + weight(u, v)
return FALSE
return TRUE
}
【Copyright】
Melodie Victoria by Kevin MacLeod is licensed under a Creative Commons Attribution 4.0 license. https://creativecommons.org/licenses/by/4.0/
Source: http://incompetech.com/music/royalty-free/index.html?isrc=USUAN1100819
Artist: http://incompetech.com/