Pagini recente » Cod sursa (job #2792851) | Cod sursa (job #196995) | Monitorul de evaluare | Cod sursa (job #1258962) | Cod sursa (job #157153)
Cod sursa(job #157153)
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
begin
writeln(fo,'NU');
exit;
end;
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.