比赛 难度范围:提高至省选 评测结果 WWWWWWWWWW
题目名称 荒野迷路 最终得分 0
用户昵称 稠翼 运行时间 0.030 s
代码语言 Pascal 内存使用 0.66 MiB
提交时间 2014-10-16 17:57:49
显示代码纯文本
program cogs1502;
type nyd=record
     n,y,d:Longint;
end;
var
   bb:array[0..500]of boolean;
   d,q:array[0..5000]of longint;
   b:array[0..30000]of nyd;
   a:array[0..30000]of longint;
   x,y,z,i,h,t,p,n,m,ii,tt,k:longint;
procedure init;
begin
     assign(input,'fieldlost.in');reset(input);
     assign(output,'fieldlost.out');rewrite(output);
end;
procedure add(x,y,z:longint);
begin
     inc(t);
     b[t].y:=y;b[t].d:=z;
     b[t].n:=a[x];a[x]:=t;
end;
procedure main;
begin
     readln(tt);
     for ii:=1 to tt do
     begin
          t:=0;
          fillchar(a,sizeof(a),0);
          fillchar(b,sizeof(b),0);
          readln(k,n,m);
          for i:=1 to m do
          begin
               readln(x,y,z);
               add(x,y,z);
               add(y,x,z);
          end;
          fillchar(q,sizeof(q),0);
          h:=0;t:=1;q[1]:=1;
          fillchar(bb,sizeof(bb),0);
          fillchar(d,sizeof(d),$0f);d[1]:=0;bb[1]:=true;
          while h<>t do
          begin
               inc(h);
               if h>5000 then h:=1;
               x:=q[h];p:=a[x];
               while p<>0 do
               begin
                    y:=b[p].y;
                    if d[x]+b[p].d<d[y] then
                    begin
                         d[y]:=d[x]+b[p].d;
                         if not bb[y] then if d[y]>d[q[h+1]] then
                         begin
                              inc(t);if t>5000 then t:=1;
                              q[t]:=y;bb[y]:=true;
                         end else
                         begin
                              q[h]:=y;bb[y]:=true;
                              dec(h);if h=0 then h:=5000;
                         end;
                    end;
                    p:=b[p].n;
               end;
               bb[x]:=false;
          end;
          if d[n]<=k then writeln('Yes!')else writeln('No!');
     end;
end;
begin
     init;
     main;
     close(output);
end.//complete by chouyi 20141016