传送门
http://cojs.tk/cogs/problem/problem.php?pid=104
http://cojs.tk/cogs/problem/problem.php?pid=105
http://cojs.tk/cogs/problem/problem.php?pid=106
http://cojs.tk/cogs/problem/problem.php?pid=107
T1 神经网络
题解
woc,尼玛这个题目的描述啊,输出非0!答案里全是输出正的!
好了,我们来简单说一下,按拓扑序的方法依次求过去即可
var
t,w:array[0..200,0..200]of longint;
ans,x,u,c,z,y:array[0..200]of longint;
i,j,k:longint;
n,m:longint;
a,b,d:longint;
begin
fillchar(y,sizeof(y),0);
readln(n,m);
for i:=1 to n do
begin readln(c[i],u[i]); end;
for i:=1 to m do
begin
readln(a,b,d);
t[a,b]:=d; w[a,b]:=1;
inc(y[b]);
end;
for i:=1 to n do
if y[i]=0 then begin
for j:=1 to n do
if w[i,j]=1 then inc(z[j]);
x[i]:=-1;
end;
for i:=1 to n do
dec(y[i],z[i]);
for i:=1 to n do
if x[i]<>-1 then c[i]:=-u[i];
repeat
k:=0;
fillchar(z,sizeof(z),0);
for i:=1 to n do
if (x[i]<>-1)and(y[i]=0) then begin
for j:=1 to n do
if (c[j]>0)and(w[j,i]=1) then begin k:=1; inc(c[i],t[j,i]*c[j]); end;
for j:=1 to n do
if (w[i,j]=1)and(x[j]<>-1)
then inc(z[j]);
x[i]:=-1;
end;
for i:=1 to n do
dec(y[i],z[i]);
until k=0;
for i:=1 to n do
begin
k:=0;
for j:=1 to n do
if (w[i,j]=1) then begin k:=1; break; end;
if (k=0) then begin inc(ans[0]); ans[ans[0]]:=i; end;
end;
k:=1;
for i:=1 to ans[0] do
if c[ans[i]]<>0 then k:=0;
if k=0 then begin
for i:=1 to ans[0] do
if c[ans[i]]>0
then writeln(ans[i],' ',c[ans[i]]); end
else writeln('NULL');
end.