Pagini recente » Cod sursa (job #1372148) | Cod sursa (job #2850014) | Cod sursa (job #1637585) | Cod sursa (job #1176150) | Cod sursa (job #157239)
Cod sursa(job #157239)
var fi,fo:text;
n,m,S,v1,v2,c,T,ns,i,j:longint;
D,p:array[1..50001]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');
for j:=1 to m do
read(fi,v1,v2,c);
exit;
end;
p[ns]:=1;
for i:=1 to n do
begin
if p[i]=0 then ok:=1;
p[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.