80分求助!!WA了!!
  • 板块P2712 摄像头
  • 楼主Hey_China
  • 当前回复5
  • 已保存回复5
  • 发布时间2023/8/6 16:37
  • 上次更新2023/11/3 05:34:22
查看原帖
80分求助!!WA了!!
680110
Hey_China楼主2023/8/6 16:37
#include <iostream>
#include <vector>
#include <queue>
using namespace std;

int ind[99999];
int oud[99999];
vector<int> a[99999];
bool o[99999];
int n;
int maxx = -1;
void topo() {
    queue<int> q;
    for(int i = 1; i <= maxx; i++){
        if(ind[i] == 0){
            q.push(i);
        }
    }
    while(!q.empty()){
        int ls = q.front();
        q.pop();
        o[ls] = 1;
        for(int i = 0; i < a[ls].size(); i++){
            int np = a[ls][i];
            if(--ind[np] == 0){
                q.push(np);
            }
        }
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    cin >> n;
    for(int i = 1; i <= n; i++){
        int e, u, v;
        cin >> e;
        maxx = max(maxx,e);
        cin >> u;
        for(int j = 1; j <= u; j++){
            cin >> v;
            a[e].push_back(v);
            ind[v]++;
            oud[e]++;
        }
    }
    topo();

    int sum = 0;
    for(int i = 1; i <= n; i++){
        if(o[i] == 0){
            sum++;
        }
    }
    if(sum == 0){
        cout << "YES";
    }else{
//    	long long len = 0;
//    	while(sum!=0){
//    		sum/=10;
//    		len++;
//		}
        cout << sum;
    }
    return 0;
}

2023/8/6 16:37
加载中...