考前最后一题,竟然是第一次码SPFA,虽然这个算法早有耳闻,甚至在闻所未闻之前自己有过一个类似的想法,说白了就是广搜啊,但是敲起来还是第一次啊,而且这还不是真正意义上的SPFA。

完全按照自己想法来码,没有看任何标程,自食其力的感觉就是舒爽…只是这样太慢,我从寒假到现在两个月也没做什么东西…做题量仅30左右,水题居多,实在是对不起自己最初的目标。

本周还经历了进高中以来的第一次数学不及格,败在立体几何上面,真是越来越觉得自己活得失败了。

有的时候还是不要想多的好,最近听了Total Eclipse of the Heart这首歌,整个人又不好了。

注意点:lol[1]:=maxlongint // 神脑残给lowcost起了个名叫lol~

program vijos_p1391;
var map:array[1..2000,1..2000] of longint;
    lol:array[1..2000] of longint;
    visit:array[1..2000] of boolean;
    q:array[1..20000] of longint;
    n,i,j,a,b,r,head,tail:longint;
function min(a,b:longint):longint;
begin
  if a<b then exit(a) else exit(b);
end;
begin
  fillchar(visit,sizeof(visit),false);
  for i:=1 to n do
    for j:=1 to n do
      map[i,j]:=maxlongint;
  readln(n);
  while true do
    begin
      readln(a,b,r);
      if (a=0) and (b=0) and (r=0) then break;
      map[a,b]:=r;
    end;
  head:=1;tail:=1;q[head]:=1;visit[1]:=true;lol[1]:=maxlongint;
  while head<=tail do
    begin
      for i:=1 to n do
        if (map[q[head],i]>0)and(lol[i]<min(map[q[head],i],lol[q[head]])) then
          begin
            lol[i]:=min(map[q[head],i],lol[q[head]]);
            if not visit[i] then
              begin
                inc(tail);
                q[tail]:=i;
                visit[i]:=true;
              end;
          end;
      visit[q[head]]:=false;inc(head);
    end;
  for i:=2 to n do
    writeln(lol[i]);
end.
想越狱的小杉

相关文章:

  • 2022-03-07
  • 2021-12-05
  • 2022-02-10
  • 2021-12-25
  • 2021-10-03
  • 2021-05-20
  • 2021-08-07
猜你喜欢
  • 2022-12-23
  • 2022-01-13
  • 2021-11-26
  • 2021-08-21
  • 2021-12-24
  • 2021-11-28
  • 2021-04-20
相关资源
相似解决方案