14572022-10-16 10:38:15HorakZsofiParti (75 pont)cpp11Accepted 75/7572ms7484 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/03ms1808 KiB
2Accepted0/037ms3576 KiB
3Accepted3/32ms2272 KiB
4Accepted3/32ms2464 KiB
5Accepted3/32ms2656 KiB
6Accepted3/32ms2912 KiB
7Accepted3/32ms3100 KiB
8Accepted4/42ms3316 KiB
9Accepted4/43ms3564 KiB
10Accepted4/43ms3644 KiB
11Accepted4/43ms3656 KiB
12Accepted4/43ms3848 KiB
13Accepted4/44ms4200 KiB
14Accepted4/44ms4084 KiB
15Accepted4/437ms5744 KiB
16Accepted4/443ms6152 KiB
17Accepted4/452ms6456 KiB
18Accepted4/461ms6556 KiB
19Accepted4/467ms7244 KiB
20Accepted4/472ms7444 KiB
21Accepted4/472ms7484 KiB
22Accepted4/42ms4664 KiB