80pts求助
查看原帖
80pts求助
218180
lighthouse楼主2021/11/24 20:11
#include <bits/stdc++.h>

using namespace std;

struct edge{
	int to;
	int w;
	int next;
}e[10001];

int head[101];

int c[101], u[101];

int in[101], out[101];

queue <int> q;

int tot;

void add(int x, int y, int z){
	tot++;
	e[tot].to = y;
	e[tot].w = z;
	e[tot].next = head[x];
	head[x] = tot;
}

int main(){
	int n, p;
	cin >> n >> p;
	for(int i = 1;i <= n;i++){
		cin >> c[i] >> u[i];
	}
	for(int i = 1;i <= p;i++){
		int x, y, z;
		cin >> x >> y >> z;
		add(x, y, z);
		in[y]++;
		out[x]++;
	}
	for(int i = 1;i <= n;i++){
		if(in[i] == 0){
			q.push(i);
		}
	}
	while(q.size()){
		int x = q.front();
		q.pop();
		for(int i = head[x];i;i = e[i].next){
			int y = e[i].to;
			int z = e[i].w;
			in[y]--;
			if(in[y] == 0){
				q.push(y);
				c[y] -= u[y];
			}
			c[y] += z * c[x];
		}
	}
	int bj = 0;
	for(int i = 1;i <= n;i++){
		cout << c[i] << " " << out[i] << " ";
		if(c[i] > 0 && out[i] == 0){
			cout << i << " " << c[i] << endl;
			bj = 1;
		}
	}
	if(bj == 0){
		cout << "NULL";
	}
	return 0;
}

WA#3

2021/11/24 20:11
加载中...