14562022-10-16 10:37:24Zoli9Parti (75 pont)cpp17Accepted 75/7574ms6800 KiB
#include <bits/stdc++.h>
using namespace std;

int main() {
	int n;
	cin>>n;
	int t[n+1][2];
	vector<int>szaml(n+1);
	vector<int>vmi;
	vector<bool>volte(n+1, false);
	for(int i=1; i<n+1; i++){
		cin>>t[i][0];
		cin>>t[i][1];
		szaml[t[i][0]]++;
		szaml[t[i][1]]++;
	}
	for(int i=1; i<n+1; i++){
		if(szaml[i]<2){
			vmi.push_back(i);
			volte[i]=true;
		}
	}
	while(!vmi.empty()){
		int u = vmi.back();
		szaml[t[u][0]]--;
		szaml[t[u][1]]--;
		vmi.pop_back();
		if(szaml[t[u][0]]<2 && !volte[t[u][0]]){
			vmi.push_back(t[u][0]);
			volte[t[u][0]]=true;
		}
		if(szaml[t[u][1]]<2 && !volte[t[u][1]]){
			vmi.push_back(t[u][1]);
			volte[t[u][1]]=true;
		}
	}
	int szamlalo=0;
	for(int x: volte){
		if(!x){
			szamlalo++;
		}
	}
	cout<<szamlalo-1<<endl;
	for(int i=1; i<n+1; i++){
		if(!volte[i]){
			cout<<i<<" ";
		}
	}
	cout << "\n";
}
SubtaskSumTestVerdictTimeMemory
base75/75
1Accepted0/03ms1816 KiB
2Accepted0/037ms3572 KiB
3Accepted3/32ms2128 KiB
4Accepted3/32ms2108 KiB
5Accepted3/32ms2320 KiB
6Accepted3/32ms2380 KiB
7Accepted3/32ms2792 KiB
8Accepted4/42ms2740 KiB
9Accepted4/43ms2900 KiB
10Accepted4/43ms2960 KiB
11Accepted4/43ms3168 KiB
12Accepted4/43ms3368 KiB
13Accepted4/44ms3448 KiB
14Accepted4/44ms3456 KiB
15Accepted4/437ms4920 KiB
16Accepted4/445ms5168 KiB
17Accepted4/452ms5548 KiB
18Accepted4/459ms5884 KiB
19Accepted4/465ms6516 KiB
20Accepted4/474ms6800 KiB
21Accepted4/472ms6724 KiB
22Accepted4/42ms3804 KiB