168062025-05-13 17:25:56algoproKét csoportcpp17Wrong answer 0/100400ms18996 KiB
// UUID: 217b7508-0ead-4ef1-a65d-c8dbbe5f6704
#include <bits/stdc++.h>
using namespace std;
vector<vector<int>> kis,ossz;
vector<int> csop;
void dfs(int cs)
{
	int hany=0;
	for(int &x:ossz[cs])
		if(csop[x]==csop[cs]) hany++;
	cout<<cs<<" "<<hany<<endl;
	if(hany<=1) return;
	if(hany==3)
	{
		csop[cs]=3-csop[cs];
		return;
	}
	csop[cs]=3-csop[cs];
	int ind=0;
	for(int &x:ossz[cs])
		if(csop[x]==csop[cs]) ind=x;
	dfs(ind); 
}
int main() {
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int n; cin>>n;
	ossz.assign(n+1,vector<int>());
	csop.assign(n+1,0);
	for(int i=1; i<=n; i++)
	{
		while(1)
		{
			int x; cin>>x;
			if(x==0) break;
			ossz[i].push_back(x);
		}
	}
	for(int i=1; i<=n; i++)
	{
		csop[i]=1;
		dfs(i);
		for(int &x:ossz[i])
		{
			if(x>i) continue;
			int hany=0;
			for(int &j:ossz[x])
				if(csop[j]==csop[x]) hany++;
			if(hany>1) dfs(x); 
		}
	}
	vector<int> ans;
	for(int i=1; i<=n; i++)
		if(csop[i]==1) ans.push_back(i);
	cout<<(int)ans.size()<<"\n";
	for(int &i:ans)
		cout<<i<<" ";
	cout<<"\n";
}
SubtaskSumTestVerdictTimeMemory
base0/100
1Wrong answer0/01ms316 KiB
2Time limit exceeded0/0310ms8108 KiB
3Wrong answer0/31ms316 KiB
4Wrong answer0/31ms316 KiB
5Wrong answer0/31ms316 KiB
6Wrong answer0/31ms316 KiB
7Wrong answer0/31ms316 KiB
8Wrong answer0/21ms316 KiB
9Wrong answer0/34ms460 KiB
10Wrong answer0/34ms316 KiB
11Wrong answer0/34ms316 KiB
12Wrong answer0/335ms1076 KiB
13Wrong answer0/335ms1076 KiB
14Wrong answer0/337ms1080 KiB
15Time limit exceeded0/6342ms8112 KiB
16Time limit exceeded0/7356ms8088 KiB
17Time limit exceeded0/7347ms8176 KiB
18Time limit exceeded0/6384ms13620 KiB
19Time limit exceeded0/6386ms13364 KiB
20Time limit exceeded0/6400ms13364 KiB
21Time limit exceeded0/6400ms18996 KiB
22Time limit exceeded0/7377ms18996 KiB
23Time limit exceeded0/7384ms18996 KiB
24Time limit exceeded0/7400ms18996 KiB