社区讨论

40 pts dalaoM 求调

P1038[NOIP 2003 提高组] 神经网络参与者 1已保存回复 0

讨论操作

快速查看讨论及其快照的属性,并进行相关操作。

当前回复
0 条
当前快照
1 份
快照标识符
@loba6wgu
此快照首次捕获于
2023/10/29 17:41
2 年前
此快照最后确认于
2023/11/03 23:38
2 年前
查看原帖
CPP
#include<bits/stdc++.h>
using namespace std;
int n, m, c[105], u[105], tmp[105][105], ru[105], chu[105], xx[105], yy[105], zz[105];
queue <int> q;
int main(){
	cin >> n >> m;
	for(int i = 1; i <= n; i++){
		cin >> u[i] >> c[i];
	}
	for(int i = 1; i <= m; i++){
		cin >> xx[i] >> yy[i] >> zz[i];
		tmp[xx[i]][yy[i]] = zz[i];
		ru[yy[i]]++;
		chu[xx[i]]++;
	}
	for(int i = 1; i <= n; i++){
		if(ru[i] == 0){
			q.push(i);
		}
	}
	while(!q.empty()){
		int y = q.front();
		q.pop();
		for(int i = 1; i <= n; i++){
			int x = tmp[y][i];
			ru[x]--;
			if(ru[x] == 0){
				q.push(i);
				c[x] -= u[x];
			}
			if(c[x] > 0){
				c[x] += zz[i]*c[x];
			}
		}
	}
	bool v = 0;
	for(int i = 1; i <= n; i++){
		if(chu[i] == 0 && c[i] > 0){
			cout << i << " " << c[i] << "\n";
			v = 1;
		}
	}
	if(v == 0){
		puts("NULL");
	}
	return 0;
}
RT

回复

0 条回复,欢迎继续交流。

正在加载回复...