Code:
#include <bits/stdc++.h>
using namespace std;
typedef long long weight;
const int maxn=105;
const weight inf=(weight)1e18;
int n,m,in[maxn],out[maxn];
weight w[maxn][maxn],c[maxn],U[maxn];
queue <int> q;
bool first[maxn];
int main()
{
ios::sync_with_stdio(0);
cin.tie(0),cout.tie(0);
cin >> n >> m;
for(int i=1;i<=n;++i)
for(int j=1;j<=n;++j)
w[i][j]=inf;
for(int i=1;i<=n;++i)
cin >> c[i] >> U[i];
for(int i=1,u,v;i<=m;++i)
cin >> u >> v >> w[u][v],++in[v],++out[u];
for(int u=1;u<=n;++u)
if(!in[u])
q.push(u),first[u]=1;
while(!q.empty())
{
int u=q.front();
q.pop();
if(c[u]<=0)
continue;
if(!first[u])
c[u]-=U[u];
for(int v=1;v<=n;++v)
{
if(in[v]<=0||w[u][v]==inf)
continue;
c[v]+=w[u][v]*c[u];
if((--in[v])==0)
q.push(v);
}
}
bool flag=0;
for(int u=1;u<=n;++u)
if(!out[u]&&c[u]>0)
cout << u << " " << c[u] << endl,flag=1;
if(!flag)
cout << "NULL" << endl;
return 0;
}
WA on #3 80pts
先在这挂着,明天再来看
睡不着闲的没事干的 dalao 来浇浇/kel