14582022-10-16 10:39:08Zoli9Parti (75 pont)cpp17Accepted 75/7529ms7332 KiB
#include <bits/stdc++.h>
using namespace std;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	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/03ms1824 KiB
2Accepted0/016ms3652 KiB
3Accepted3/32ms2288 KiB
4Accepted3/32ms2364 KiB
5Accepted3/32ms2496 KiB
6Accepted3/32ms2696 KiB
7Accepted3/32ms2876 KiB
8Accepted4/42ms3048 KiB
9Accepted4/42ms3284 KiB
10Accepted4/43ms3644 KiB
11Accepted4/42ms4084 KiB
12Accepted4/43ms3732 KiB
13Accepted4/43ms3828 KiB
14Accepted4/43ms3828 KiB
15Accepted4/416ms5608 KiB
16Accepted4/418ms5580 KiB
17Accepted4/420ms5824 KiB
18Accepted4/424ms6156 KiB
19Accepted4/427ms6984 KiB
20Accepted4/429ms6984 KiB
21Accepted4/429ms7332 KiB
22Accepted4/42ms4364 KiB