https://www.luogu.com.cn/problem/P1038
#include <iostream> #include<queue> #include <vector> #include <cstring> using namespace std; const int N=104, M=1e5; int nxt[M],go[M],hd[N],w[M],all=1; int n,m,U[N],C[N]; int in[N],out[N]; void add_(int x,int y,int z){ nxt[++all]=hd[x]; hd[x]=all; go[all]=y; w[all]=z; } void solve(){ int i,x; queue<int> q; for(i=1;i<=n;i++) if(in[i]==0) q.push(i); while(q.empty()==0){ x=q.front(); q.pop(); if(C[x]<0) continue ; for(i=hd[x];i;i=nxt[i]){ int y=go[i],z=w[i]; --in[y]; if(C[x]>0) C[y]+=z*C[x]; if(in[y]==0) q.push(y); } } int fg=0; for(i=1;i<=n;i++){ if(C[i]>0&& out[i]==0) {fg=1; break;} } if(fg==0){ cout<<"NULL\n";return; } for(i=1;i<=n;i++){ if(out[i]==0&&C[i]>0) cout<<i<<' '<<C[i]<<endl; } } signed main(){ int i; cin>>n>>m; for(i=1;i<=n;i++){ cin>>C[i]>>U[i]; if(C[i]==0) C[i]-=U[i]; } for(i=1;i<=m;i++){ int x,y,z; cin>>x>>y>>z; add_(x,y,z); out[x]++,in[y]++; } solve(); }
标签:P1038,NOIP2003,int,神经网络,fg,include,hd,out From: https://www.cnblogs.com/towboa/p/17203020.html