Pagini recente » Cod sursa (job #3256280) | Cod sursa (job #699431) | Cod sursa (job #1288729) | Cod sursa (job #2336809) | Cod sursa (job #157166)
Cod sursa(job #157166)
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])and(v2<>ns) then ok:=1;
if (d[v2]+c<d[v1])and(v1<>ns) 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.