14552022-10-16 10:30:22HorakZsofiParti (75 pont)cpp11Wrong answer 72/7575ms14212 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<<" ";
		}
	}
}
SubtaskSumTestVerdictTimeMemory
base72/75
1Accepted0/03ms1936 KiB
2Accepted0/039ms4228 KiB
3Accepted3/32ms2904 KiB
4Accepted3/32ms3004 KiB
5Wrong answer0/32ms3140 KiB
6Accepted3/32ms3380 KiB
7Accepted3/32ms3552 KiB
8Accepted4/42ms3796 KiB
9Accepted4/43ms3852 KiB
10Accepted4/43ms4152 KiB
11Accepted4/43ms4220 KiB
12Accepted4/43ms4412 KiB
13Accepted4/44ms4528 KiB
14Accepted4/44ms4880 KiB
15Accepted4/439ms6828 KiB
16Accepted4/448ms7804 KiB
17Accepted4/452ms8988 KiB
18Accepted4/461ms10040 KiB
19Accepted4/468ms11796 KiB
20Accepted4/475ms13128 KiB
21Accepted4/475ms14212 KiB
22Accepted4/42ms11444 KiB