讨论 / AC100 Pascal
jxxx3341 2017-10-12 09:01:14
点我顶贴 收藏 删除
测试点1 Accepted / 0ms / 324kB

测试点2 Accepted / 0ms / 324kB

测试点3 Accepted / 0ms / 324kB

测试点4 Accepted / 0ms / 324kB

测试点5 Accepted / 0ms / 324kB

测试点6 Accepted / 0ms / 324kB

测试点7 Accepted / 0ms / 324kB

测试点8 Accepted / 0ms / 324kB

测试点9 Accepted / 0ms / 324kB

测试点10 Accepted / 0ms / 324kB

var

n,m,x,y,l,z,h,tl :longint;

cur,p,q :longint;

i :longint;

b :boolean;

last,c,u,indu,outdu :array[0..110] of longint;

virus,shuru :array[0..110] of boolean;

que :array[0..110] of longint;

pre,other,len :array[0..1010] of longint;

procedure connect(x,y,z:longint);

begin

inc(l);

pre[l]:=last[x];

last[x]:=l;

other[l]:=y;

len[l]:=z;

end;

begin

read(n,m);

for i:=1 to n do read(c[i],u[i]);

for i:=1 to m do

begin

read(x,y,z);

connect(x,y,z);

inc(indu[y]);

inc(outdu[x]);

end;

for i:=1 to n do if (indu[i]=0) then

begin

inc(tl);

que[tl]:=i;

virus[i]:=true;

shuru[i]:=true;

end;

h:=0;

while (h<>tl) do

begin

h:=h mod 100+1;

cur:=que[h];

virus[cur]:=false;

q:=last[cur];

if not shuru[cur] then c[cur]:=c[cur]-u[cur];

while (q<>0) do

begin

p:=other[q];

dec(indu[p]);

if c[cur]>0 then c[p]:=c[p]+len[q]*c[cur];

if (indu[p]=0) and not virus[p] then

begin

tl:=tl mod 100+1;

virus[p]:=true;

que[tl]:=p;

end;

q:=pre[q];

end;

end;

for i:=1 to n do

if (c[i]>0) and (outdu[i]=0) then

begin

writeln(i,' ',c[i]);b:=true;

end;

if not b then writeln('NULL');

end.

查看更多回复
提交回复