HELP!
  • 板块P2712 摄像头
  • 楼主hgfs
  • 当前回复0
  • 已保存回复0
  • 发布时间2024/7/16 17:49
  • 上次更新2024/7/16 17:50:59
查看原帖
HELP!
1124438
hgfs楼主2024/7/16 17:49

有些边界就是老是错,#5多一个,#6少一个,#9少两个。

#include<bits/stdc++.h>
using namespace std;

int n,e[200002],ne[200002],h[200002],hm[200002],idx,k;
bool st[200002];
queue<int> q;

void add(int a,int b){
 	e[idx]=b;
 	ne[idx]=h[a];
	h[a]=idx++;
}

int main(){
	memset(h,-1,sizeof(h));
	cin>>n;
	int a,b,c;
	for(int i=1;i<=n;i++){
		cin>>a>>b;
		while(b){
			cin>>c;
			add(a,c);
			hm[c]++;
			b--;
		}
		st[a]++;
	}
	for(int i=1;i<=n;i++) if(!hm[i]) q.push(i);
	while(!q.empty()){
		int p=q.front();
		q.pop();
		k++;
		for(int i=h[p];~i;i=ne[i]){
			int j=e[i];
			hm[j]--;
			if(!hm[j] && st[j]) q.push(j);
		}
	}
	if(k==n) cout<<"YES";
	else cout<<n-k;
	return 0;
}

为什么不能下载数据

2024/7/16 17:49
加载中...