99912024-03-23 17:42:21111Két csoportcpp17Runtime error 35/100266ms74344 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 dfs=[&](auto self,int i)->void{
		array<vector<int>,3>a;
		for(int j:g[i]){
			a[v[j]].push_back(j);
		}
		v[i]=a[1].size()<=a[2].size()?1:2;
		for(int j:a[0]){
			self(self,j);
		}
	};
	for(int i=1;i<=N;i++){
		if(v[i]){
			continue;
		}
		dfs(dfs,i);
	}
	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
base35/100
1Accepted0/03ms1828 KiB
2Accepted0/064ms16936 KiB
3Accepted3/33ms2268 KiB
4Accepted3/33ms2372 KiB
5Accepted3/33ms2580 KiB
6Accepted3/33ms2708 KiB
7Accepted3/33ms2760 KiB
8Accepted2/23ms2780 KiB
9Accepted3/33ms3156 KiB
10Runtime error0/33ms3428 KiB
11Runtime error0/33ms3556 KiB
12Accepted3/38ms5064 KiB
13Runtime error0/38ms5444 KiB
14Runtime error0/310ms7196 KiB
15Accepted6/667ms20524 KiB
16Runtime error0/771ms22288 KiB
17Runtime error0/785ms36924 KiB
18Accepted6/6135ms41816 KiB
19Runtime error0/6138ms45776 KiB
20Runtime error0/6177ms74344 KiB
21Time limit exceeded0/6203ms69288 KiB
22Time limit exceeded0/7210ms72472 KiB
23Time limit exceeded0/7254ms64724 KiB
24Time limit exceeded0/7266ms64668 KiB