123
2023-07-16 20:25:31
发布于:浙江
#include<bits/stdc++.h>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<stack>
using namespace std;
typedef long long ll;
const int inf = 5000005;
struct edge {
int to, val, nxt;
} e[10005];
struct answer {
int id, val;
} ans[105];
int h, i, m, n, t, u, v, w, U, c[105], hd[105], out[105], vis[105];
queue<int> q;
int cnt = 0, flag = 0;
inline bool cmp(answer aa, answer bb) { return aa.id < bb.id; }
inline void build(int u, int v, int w) {
cnt++;
e[cnt].to = v;
e[cnt].val = w;
e[cnt].nxt = hd[u];
hd[u] = cnt;
}
int main() {
ios::sync_with_stdio(false);
cin >> n >> m;
for (i = 1; i <= n; i++) {
vis[i] = out[i] = 0;
cin >> c[i] >> U;
if (c[i] > 0) {
q.push(i);
vis[i] = 1;
} else c[i] -= U;
}
for (i = 1; i <= m; i++) {
cin >> u >> v >> w;
build(u, v, w);
out[u] = 1;
}
while (!q.empty()) {
h = q.front();
q.pop();
if (c[h] <= 0) continue;
for (i = hd[h]; i; i = e[i].nxt) {
t = e[i].to;
c[t] += e[i].val * c[h];
if (!vis[t]) {
q.push(t);
vis[t] = 1;
}
}
}
for (i = 1; i <= n; i++)
if (!out[i] && c[i] > 0) {
cout << i << " " << c[i] << endl;
flag = 1;
}
if (!flag) {
cout << "NULL" << endl;
return 0;
}
return 0;
}
这里空空如也
有帮助,赞一个