[vijos P1391] 想越狱的小杉

考前最后一题,竟然是第一次码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.
想越狱的小杉

测试数据 #0: Accepted, time = 0 ms, mem = 16476 KiB, score = 10

测试数据 #1: Accepted, time = 0 ms, mem = 16476 KiB, score = 10

测试数据 #2: Accepted, time = 0 ms, mem = 16476 KiB, score = 10

测试数据 #3: Accepted, time = 78 ms, mem = 16476 KiB, score = 10

测试数据 #4: Accepted, time = 93 ms, mem = 16480 KiB, score = 10

测试数据 #5: Accepted, time = 62 ms, mem = 16476 KiB, score = 10

测试数据 #6: Accepted, time = 78 ms, mem = 16476 KiB, score = 10

测试数据 #7: Accepted, time = 62 ms, mem = 16476 KiB, score = 10

测试数据 #8: Accepted, time = 78 ms, mem = 16476 KiB, score = 10

测试数据 #9: Accepted, time = 93 ms, mem = 16476 KiB, score = 10

SPFA果然很快,神速=w=。

对难题不抱什么希望了,只求暴力啦模拟啦朴素啦细心啦之类的可以有分~Anything that's worth having, is sure enough worth fighting for.

原文地址:https://www.cnblogs.com/Sky-Grey/p/3631907.html