标签:
#include<iostream>
using namespace std;
bool ans[2001],not_last[2001];
int c[2001],w[201][2001],u[2001],before[2001][2001];
int n,i,j,p,seve;
void find(int x){
if (c[x]!=0) return;
int i;
for (i=1;i<=before[x][0];++i){
int j;
j=before[x][i];
find(j);
if (c[j]>0) c[x]+=w[j][x]*c[j];
}
c[x]-=u[x];
}
int main(){
cin>>n>>p;
for (i=1;i<=n;++i) cin>>c[i]>>u[i];
for (i=1;i<=p;++i){
int a,b,c;
cin>>a>>b>>c;
w[a][b]=c;
before[b][++before[b][0]]=a;
not_last[a]=true;
}
for (i=1;i<=n;++i)
if (not_last[i]==false)
find(i);
bool can=false;
for (i=1;i<=n;++i)
if ((not_last[i]==false)&&(c[i]>0)){
ans[i]=true;
can=true;
}
if (can)
for (i=1;i<=n;++i)
if (ans[i]) cout<<i<<" "<<c[i]<<endl;
else {}
else cout<<"NULL"<<endl;
return 0;
}
标签:
原文地址:http://www.cnblogs.com/DZRDerek/p/5968014.html