99942024-03-23 18:34:03111Két csoportcpp17Runtime error 15/100200ms63340 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{
		for(int j:g[i]){
			if(a[j]){
				continue;
			}
			a[j]=-1;
			self(self,j);
		}
		int c=0;
		for(int j:g[i]){
			if(a[j]==1){
				c++;
				for(int k:g[j]){
					if(a[k]==1){
						c++;
					}
				}
			}
		}
		a[i]=c>1?2:1;
	};
	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
base15/100
1Accepted0/03ms1828 KiB
2Runtime error0/054ms17352 KiB
3Accepted3/33ms2328 KiB
4Accepted3/33ms2480 KiB
5Accepted3/33ms2560 KiB
6Accepted3/33ms2656 KiB
7Accepted3/33ms2888 KiB
8Runtime error0/23ms3092 KiB
9Runtime error0/33ms3500 KiB
10Runtime error0/33ms3724 KiB
11Runtime error0/33ms3992 KiB
12Runtime error0/38ms5448 KiB
13Runtime error0/38ms5488 KiB
14Runtime error0/38ms6080 KiB
15Runtime error0/654ms19416 KiB
16Runtime error0/759ms19904 KiB
17Runtime error0/765ms23992 KiB
18Runtime error0/6104ms35076 KiB
19Runtime error0/6118ms35896 KiB
20Runtime error0/6131ms43188 KiB
21Runtime error0/6157ms50116 KiB
22Runtime error0/7175ms50788 KiB
23Runtime error0/7199ms59568 KiB
24Runtime error0/7200ms63340 KiB