99952024-03-23 18:42:16111Két csoportcpp17Runtime error 41/100187ms59540 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);
	auto dfs1=[&](auto self,int i)->void{
		for(int j:g[i]){
			if(v[j]){
				continue;
			}
			v[j]=v[i]^3;
			self(self,j);
		}
	};
	vector<int>a(N+1);
	auto dfs2=[&](auto self,int i)->void{
		int c=0;
		for(int j:g[i]){
			if(a[j]==v[i]){
				c++;
			}
		}
		if(c>1){
			a[i]=v[i]^3;
		}
		else{
			a[i]=v[i];
		}
		for(int j:g[i]){
			if(a[j]){
				continue;
			}
			self(self,j);
		}
	};
	for(int i=1;i<=N;i++){
		if(v[i]){
			continue;
		}
		v[i]=1;
		a[i]=1;
		dfs1(dfs1,i);
		dfs2(dfs2,i);
	}
	for(int i=1;i<=N;i++){
		int c=0;
		for(int j:g[i]){
			if(a[j]==a[i]){
				c++;
			}
		}
		if(c>1){
			exit(1);
		}
	}
	vector<int>ans;
	for(int i=1;i<=N;i++){
		if(a[i]==1){
			ans.push_back(i);
		}
	}
	cout<<ans.size()<<'\n';
	for(int i:ans){
		cout<<i<<' ';
	}
	cout<<'\n';
	return 0;
}
SubtaskSumTestVerdictTimeMemory
base41/100
1Accepted0/03ms1828 KiB
2Accepted0/059ms18444 KiB
3Accepted3/33ms2356 KiB
4Accepted3/33ms2436 KiB
5Accepted3/33ms2512 KiB
6Accepted3/33ms2636 KiB
7Accepted3/33ms2716 KiB
8Accepted2/23ms2716 KiB
9Accepted3/33ms2808 KiB
10Runtime error0/33ms2952 KiB
11Runtime error0/33ms2908 KiB
12Accepted3/38ms4544 KiB
13Runtime error0/38ms4660 KiB
14Runtime error0/38ms4888 KiB
15Accepted6/659ms19332 KiB
16Runtime error0/756ms18432 KiB
17Runtime error0/761ms21540 KiB
18Accepted6/6118ms35532 KiB
19Runtime error0/6112ms34260 KiB
20Runtime error0/6125ms40716 KiB
21Accepted6/6177ms53292 KiB
22Runtime error0/7167ms49524 KiB
23Runtime error0/7187ms56776 KiB
24Runtime error0/7187ms59540 KiB