70求调 WA#5#6#9
查看原帖
70求调 WA#5#6#9
1032499
jintingze123楼主2024/11/22 20:26
#include<bits/stdc++.h>
using namespace std;
vector<int>e[1005] ;
queue<int>q ;
int n,m,ind[1005],x,y,o,flag=0,ans=0 ;
int main(){
	cin >> n >> m ;
    for(int i = 1 ; i <= m ; i++){
        cin >> x >> o ;
        for(int j = 1 ; j <= o ; j++){
            cin >> y ;
            ind[y]++ ;
            e[x].push_back(y);//输入
        }
    }
	for(int i = 1; i <= n; i++)if(ind[i] == 0)q.push(i);//记录ind为0的点
	while(!q.empty()){
	    ans++ ;//记数
		int u = q.front();
		q.pop();
		for(int i = 0; i < e[u].size(); i++){
			int v = e[u][i];
			ind[v]--;
			if(ind[v] == 0)q.push(v);//拆掉
		}
	}
	if(ans==n)cout<<"YES";
	else cout << n-ans;
	return 0;
}
2024/11/22 20:26
加载中...