Pagini recente » Cod sursa (job #2896408) | Cod sursa (job #1516158) | Cod sursa (job #3192254) | Cod sursa (job #1077080) | Cod sursa (job #629268)
Cod sursa(job #629268)
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:=1 to m do readln(fi,a[i].x,a[i].y,a[i].t);
for i:=1 to n do v[i]:=-1;
v[s]:=0; ok:=true;
while ok do begin
ok:=false;
for i:=1 to m 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.