noip2003神经网络【Pascal】

这题就是个拓扑排序,注意题目要求:

1、输入层的c[i]按照输入所给直接传递,不需要用公式-u[i]

    (其实也没办法用公式,输入层入度为0,没有边连入)

2、答案是最后状态非0的输出层(出度为0)

3、只有当c[i]>0的时候才向下传递,只有此时对于它所连的点才使用公式

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;
        vis,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;
      vis[i]:=true;
      shuru[i]:=true;
   end;
   h:=0;
   //
   while (h<>tl) do
   begin
      h:=h mod 100+1;
      cur:=que[h];
      vis[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 vis[p] then
         begin
            tl:=tl mod 100+1;
            vis[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.	
——by Eirlys
转载请注明出处=w=


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值