Pagini recente » Cod sursa (job #3041392) | Cod sursa (job #1633383) | Cod sursa (job #719683) | Cod sursa (job #1796182) | Cod sursa (job #796563)
Cod sursa(job #796563)
Program p2;
var fi,fo:text;
t:0..15;
i,n,m,s:longint;
a,b,c,d,q1,q2:array[0..50005] of longint;
Procedure dijkstra;
var i:integer; t:boolean;
begin
t:=true;
while t do begin
t:=false;
for i:=1 to m do
if (q2[a[i]]<>-1) and ((q2[b[i]]>q2[a[i]]+c[i]) or (q2[b[i]]=-1))
then begin
t:=true;
q2[b[i]]:=q2[a[i]]+c[i];
end;
end;
t:=true;
for i:=1 to n do if (q1[i]<>q2[i]) then t:=false;
if t=true then writeln(fo,'DA')
else writeln(fo,'NU');
end;
begin
assign(fi,'distante.in'); reset(fi);
assign(fo,'distante.out'); rewrite(fo);
readln(fi,t);
while t>0 do begin
readln(fi,n,m,s);
for i:=1 to n do begin read(fi,q1[i]); q2[i]:=-1; end;
q2[s]:=0;
for i:=1 to m do readln(fi,a[i],b[i],c[i]);
dijkstra;
readln(fi);
dec(t);
end;
close(fi); close(fo);
end.