99922024-03-23 18:01:21111Két csoportcpp17Runtime error 33/100246ms66956 KiB
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
#ifndef ONLINE_JUDGE
	freopen("be2.txt","r",stdin);
#endif
	int N;
	cin>>N;
	vector<vector<int>>g(N+1);
	for(int i=1;i<=N;i++){
		for(int j;cin>>j,j;){
			g[i].push_back(j);
		}
	}
	vector<int>v(N+1);
	deque<int>q;
	for(int i=1;i<=N;i++){
		if(v[i]){
			continue;
		}
		v[i]=1;
		q.push_back(i);
		while(!q.empty()){
			int j=q.front();
			q.pop_front();
			array<vector<int>,3>a;
			for(int k:g[j]){
				a[v[k]].push_back(k);
			}
			v[j]=a[1].size()<=a[2].size()?1:2;
			for(int k:a[0]){
				q.push_back(k);
			}
		}
	}
	for(int i=1;i<=N;i++){
		int c=0;
		for(int j:g[i]){
			if(v[j]==v[i]){
				c++;
			}
		}
		if(c>1){
			exit(1);
		}
	}
	vector<int>ans;
	for(int i=1;i<=N;i++){
		if(v[i]==1){
			ans.push_back(i);
		}
	}
	cout<<ans.size()<<'\n';
	for(int i:ans){
		cout<<i<<' ';
	}
	cout<<'\n';
	return 0;
}
SubtaskSumTestVerdictTimeMemory
base33/100
1Accepted0/03ms2100 KiB
2Accepted0/068ms17060 KiB
3Accepted3/33ms2336 KiB
4Accepted3/33ms2460 KiB
5Accepted3/33ms2644 KiB
6Accepted3/33ms2852 KiB
7Accepted3/33ms3232 KiB
8Runtime error0/23ms3352 KiB
9Accepted3/33ms3736 KiB
10Runtime error0/33ms3988 KiB
11Runtime error0/33ms4064 KiB
12Accepted3/38ms5396 KiB
13Runtime error0/38ms5240 KiB
14Runtime error0/38ms5720 KiB
15Accepted6/664ms19228 KiB
16Runtime error0/768ms19688 KiB
17Runtime error0/778ms22448 KiB
18Accepted6/6141ms37128 KiB
19Runtime error0/6136ms38664 KiB
20Runtime error0/6162ms44520 KiB
21Time limit exceeded0/6221ms64652 KiB
22Time limit exceeded0/7217ms63520 KiB
23Time limit exceeded0/7246ms66904 KiB
24Time limit exceeded0/7246ms66956 KiB