Cod sursa(job #629263)

Utilizator ctlin04UAIC.VlasCatalin ctlin04 Data 2 noiembrie 2011 23:59:51
Problema Distante Scor 0
Compilator fpc Status done
Runda Arhiva de probleme Marime 1.14 kb
Program distante;
 type tip=record
        x,y,t:longint;
        end;
var  a:array [0..50000] of tip;
     v,c:array [0..50000] of longint;
     b1,b2:array [1..1 shl 17] of char;
     n,m,i,t,j,s:longint;
     ok,okk:boolean;
     fi,fo:text;
begin
 assign(fi,'distante.in');
  assign(fo,'distante.out');
 settextbuf(fi,b1);
  settextbuf(fo,b2);
 reset(fi); rewrite(fo);
 readln(fi,t);
 for j:=1 to t do begin
   readln(fi,n,m,s);
    for i:=1 to n do read(fi,c[i]); readln(fi);
     for i:=0 to m-1 do readln(fi,a[i].x,a[i].y,a[i].t);
    for i:=0 to n do v[i]:=-1;
     v[s]:=0; ok:=true;
  while ok do begin
              ok:=false;
              for i:=0 to m-1 do
               if (v[a[i].x]<>-1) and ((v[a[i].y]=-1) or (v[a[i].y]>v[a[i].x]+a[i].t)) then
                begin
                 v[a[i].y]:=v[a[i].x]+a[i].t;
                 ok:=true;
                 end;
          end;
          okk:=true;
  for i:=1 to n do
   if v[i]=-1 then begin if c[i]<>0 then okk:=false; end
    else if c[i]<>v[i] then okk:=false;
  if okk then writeln(fo,'DA')
          else writeln(fo,'NU');
  end;
 close(fo);
end.