标签:style blog color io for ar cti div
有SPFA模板,bellman-ford模板显然是多余的。
var e:array[1..maxe]of record a,b,w:longint;end; { 距源点s距离 } dis:array[1..maxn]of longint; { 前驱 } pre:array[1..maxn]of longint; m,n,s:longint; procedure relax(u,v,w:longint); begin if dis[u]+w<dis[v] then begin dis[v]:=dis[u]+w; pre[v]:=u; end; end; function bellman_ford:boolean; var i,j:longint; begin { 每条边松弛 } for i:=1 to n-1 do for j:=1 to m do with e[j] do relax(a,b,w); { 如果还能松弛 } for i:=1 to m do with e[i] do if dis[a]+w<dis[b] then exit(false); exit(true) end;
bellman-ford算法模板,布布扣,bubuko.com
标签:style blog color io for ar cti div
原文地址:http://www.cnblogs.com/cuichen/p/3918364.html