Pagini recente » Cod sursa (job #3196427) | Cod sursa (job #862649) | Cod sursa (job #1617683) | Cod sursa (job #2735863) | Cod sursa (job #382137)
Cod sursa(job #382137)
{distante pagina 167}
const inf=maxlongint div 2;
type vector=array[1..50000] of longint;
muchie=record
x,y,c:longint;
end;
var t:byte;
function la_fel(vezi,d:vector; n:longint):boolean;
var i:longint;
begin
la_fel:=true;
for i:=1 to n do
if vezi[i]<>d[i] then
begin
la_fel:=false;
exit;
end;
end;
procedure rezolvare(n,m,s:longint);
var d,vezi:vector;
marcat:bool;
u:array[1..100000] of muchie;
i:longint;
ok:boolean;
begin
for i:=1 to n do
begin
read(vezi[i]);
d[i]:=inf;
end;
for i:=1 to m do read(u[i].x,u[i].y,u[i].c);
d[s]:=0;
ok:=true;
while ok do
for i:=1 to m do
if d[u[i].y]>d[u[i].x]+u[i].c then
begin
d[u[i].y]:=d[u[i].x]+u[i].c;
ok:=false;
end;
for i:=1 to n do
if d[i]=inf then d[i]:=0;
if la_fel(vezi,d,n) then writeln('DA')
else writeln('NU');
end;
procedure citire;
var i:byte;
n,m,s:longint;
begin
assign(input,'distante.in'); reset(input);
assign(output,'distante.out'); rewrite(output);
readln(t);
for i:=1 to t do
begin
readln(n,m,s);
rezolvare(n,m,s);
end;
close(input);
close(output);
end;
begin
citire;
end.