显示代码纯文本
#include<cstdio>
#include<queue>
#include<vector>
#define syy myson
using namespace std;
const int maxn=201;
int n,p,u[maxn],c[maxn],w[maxn][maxn],inque[maxn],i,j;
queue<int>q;
vector<int>v[maxn];
int Main()
{
freopen("sjwl.in","r",stdin);freopen("sjwl.out","w",stdout);
scanf("%d%d",&n,&p);
for(i=1;i<=n;i++)
{
scanf("%d%d",&c[i],&u[i]);
if(c[i]>0)
{
q.push(i);
inque[i]=1;
}
}
while(p--)
{
int a,b,c;
scanf("%d%d%d",&a,&b,&c);
v[a].push_back(b);
w[a][b]=c;
}
while(!q.empty())
{
int now=q.front();
q.pop();
if(c[now]>0)
for(i=0;i<v[now].size();i++)
{
int to=v[now][i];
c[to]+=(w[now][to]*c[now]);
if(!inque[to])
{
c[to]-=u[to];
q.push(to);
inque[to]=1;
}
}
}
int no=1;
for(i=1;i<=n;i++)
if((v[i].size()==0)&&(c[i]>0))
{
printf("%d %d\n",i,c[i]);
no=0;
}
if(no)printf("NULL\n");
return 0;
}
int main(){;}
int syy=Main();