Cod sursa(job #157144)

Utilizator Pepelea_FlaviuFlaviu Pepelea Pepelea_Flaviu Data 12 martie 2008 21:27:07
Problema Distante Scor 20
Compilator fpc Status done
Runda Arhiva de probleme Marime 0.91 kb
var fi,fo:text;
    n,m,S,v1,v2,c,T,ns,i,j:longint;
    D,p:array[1..50000]of longint;
procedure verif(tt:longint);
var i,ok:longint;
begin
  ok:=0;
  if d[ns]=0 then
    begin
      for j:=1 to m do
         begin
           read(fi,v1,v2,c);
           if d[v1]+c<d[v2] then ok:=1;
           if d[v2]+c<d[v1] then ok:=1;
           if (d[v1]+c=d[v2]) then inc(p[v2]);
           if (d[v2]+c=d[v1]) then inc(p[v1]);
         end;
    end
 else writeln(fo,'NU');
 for i:=1 to n do
   if i<>ns then
     begin
       if d[i]=0 then ok:=1;
       d[i]:=0;
     end;
 if ok=1 then writeln(fo,'NU')
         else writeln(fo,'DA');
end;
begin
  assign(fi,'distante.in'); reset(fi);
  assign(fo,'distante.out'); rewrite(fo);
  read(fi,T);
  for i:=1 to T do
    begin
      read(fi,n,m,ns);
      for j:=1 to n do
        read(fi,d[j]);
      verif(i);
    end;
  close(fi);
  close(fo);
end.