您的位置:首页 > 其它

1328. Party (Standard IO)

2016-07-09 07:49 295 查看


Description

  N头牛要去参加一场在编号为x(1<=x<=n)的牛的农场举行的派对(1<=N<=1000),有M(1<=m<=100000)条有向道路,每条路长ti(1<=ti<=100);

  每头牛都必须参加完派对后回到家,每头牛都会选择最短路径,求这n个牛的最短路径(一个来回)中最长的一条的长度。

  特别提醒:可能有权值不同的重边。

题解:

      赤裸裸的SPFA,一正一反。

代码:

procedure spfa;

var

  h,t,i:longint;

begin

  h:=0;t:=1;list[1]:=1;v[1]:=1;

  repeat

    h:=h mod n+1;

    i:=lastside[list[h]];

    while i>0 do

      begin

        if d[x[i]]+w[i]<d[y[i]] then

          begin

            d[y[i]]:=d[x[i]]+w[i];

            if v[y[i]]=0 then

              begin

                t:=t mod n+1;

                v[y[i]]:=1;

                list[t]:=y[i];

              end;

          end;

        i:=next[i];

      end;

    v[list[h]]:=0;

  until h=t;

end;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  1328