/ Vijos / 讨论 / 分享 /

关于SPFA

本人不太懂SPFA,有哪个牛能给讲讲吗?

PS:最好有标程

2 条评论

  • @ 2009-03-17 15:19:01

    顶顶……

  • @ 2009-03-16 17:33:44

    这是我做的spfa

    var cost:array[1..100,1..100]of longint;

    dist:array[1..100]of longint;

    vis:array[1..100]of boolean;

    q:array[1..10000]of integer;

    n,m,h,t,x:integer;

    procedure init;

    var i,j,k,m:integer;

    begin

    readln(n,m);

    for i:=1 to m do readln(j,k,cost[j,k]);

    for i:=1 to n do

    for j:=i to n do cost[j,i]:=maxint;

    for i:=1 to n do dist[i]:=maxint;

    dist[1]:=0;

    end;

    procedure spfa;

    var i:integer;

    begin

    t:=1;q[t]:=1;vis[1]:=true;

    repeat

    inc(h);x:=q[h];vis[h]:=false;

    for i:=1 to n do

    if(cost[x,i]0)and(dist[x]+cost[x,i]

  • 1