WA on #3 #5 求助
查看原帖
WA on #3 #5 求助
556362
Unnamed114514楼主2022/5/14 00:10
#include<bits/stdc++.h>
using namespace std;
int n,p,tot,cnt[205],cnt2[205],c[205],u[205];
struct edge{
	int to,val;
};
queue<int> q;
vector<edge> G[205];
inline int read(){
    int res=0,f=0;
    char ch=getchar();
    while(ch<'0'||ch>'9'){
    	f|=(ch=='-');
        ch=getchar();
    }
    while(ch>='0'&&ch<='9'){
        res=(res<<1)+(res<<3)+(ch^'0');
        ch=getchar();
    }
    return f?-res:res;
}
inline void TopSort(){
	for(int i=1;i<=n;++i)
		if(!cnt[i])
			q.push(i);
	while(!q.empty()){
		int u=q.front();
		q.pop();
		for(int i=0,len=G[u].size();i<len;++i){
			int v=G[u][i].to,w=G[u][i].val;
			c[v]+=w*c[u];
			--cnt[v];
			if(!cnt[v])
				q.push(v);
		}
	}
}
int main(){
	n=read(),p=read();
	for(int i=1;i<=n;++i)
		c[i]=read(),u[i]=read(),c[i]-=u[i];
	for(int i=1;i<=p;++i){
		int u=read(),v=read(),w=read();
		G[u].push_back(edge({v,w}));
		++cnt[v];
		++cnt2[u];
	}
	TopSort();
	for(int i=1;i<=n;++i)
		if(!cnt2[i]&&c[i]>0){
			++tot;
			printf("%d %d\n",i,c[i]);
		}
	if(!tot)
		puts("NULL");
	return 0;
}
2022/5/14 00:10
加载中...