调不出哪有问题,求助!
查看原帖
调不出哪有问题,求助!
948326
Sherrymini楼主2024/8/25 13:47
#include <bits/stdc++.h>
using namespace std;
int n,p,c[105],u[105],out[105],vis[105],now,t,u1,v,w;
int main(){
    cin >> n >> p;
    queue <int>q;
    vector <int>a,val;
    for(int i = 1;i <= n;i++){
        cin >> c[i] >> u[i];
        if(c[i]){
            q.push(i);
            vis[i] = 1;
        }else{
            c[i] -= u[i];
            vis[i] = 0;
        }
    }
    for(int i = 1;i <= p;i++){
        cin >> u1 >> v >> w;
        a.push_back(v);
        val.puah_back(w);
        out[u1] = i;
    }
    while(!q.empty()){
        now = q.front();
        q.pop();
        if(c[now] <= 0) continue;
        for(int i = 0;i < a[now].size();i++){
            t = a[now][i];
            c[t] += c[now] * val[now][i];
            if(!vis[t]){
                q.push(t);
                vis[t] = 1;
            }
        }
    }
    bool flag = 0;
    for(int i = 1;i <= n;i++){
        if(out[i] == 0 && c[i] > 0){
            printf("%d %d\n",i,c[i]);
            flag = 1;
        }
    }
    if(!flag) printf("NULL");
    return 0;
}
2024/8/25 13:47
加载中...