25062023-01-14 19:59:15JMMirkoParti (75 pont)cpp17Accepted 75/7575ms6996 KiB
// Source: https://usaco.guide/general/io

#include <bits/stdc++.h>
using namespace std;

int main() {
	int n;
	cin >> n;
	vector<pair<int,int> > v;
	vector<int> ve(n);
	queue<int> q;
	for(int i=0;i<n;i++){
		int a,b;
		cin >> a >> b;
		v.push_back(make_pair(a-1,b-1));
		ve[a-1]++;
		ve[b-1]++;
	}
	for(int i=0;i<n;i++){
		if(ve[i]<2)q.push(i);
	}
	while(!q.empty()){
		int a=q.front();
		q.pop();
		ve[v[a].first]--;
		ve[v[a].second]--;
		if(ve[v[a].first]==1)q.push(v[a].first);
		if(ve[v[a].second]==1)q.push(v[a].second);
	}
	//for(int x:ve)cout << x << " ";
	//cout << endl;
	vector<int>vec;
	for(int i=0;i<n;i++){
		if(ve[i]>1)vec.push_back(i);
	}
	cout << vec.size() << endl;
	for(int x:vec)cout << x+1 << ' ';
	cout << endl;
}
SubtaskSumTestVerdictTimeMemory
base75/75
1Accepted0/03ms1812 KiB
2Accepted0/037ms3756 KiB
3Accepted3/32ms2260 KiB
4Accepted3/32ms2460 KiB
5Accepted3/32ms2540 KiB
6Accepted3/32ms2620 KiB
7Accepted3/32ms2692 KiB
8Accepted4/42ms2832 KiB
9Accepted4/43ms3044 KiB
10Accepted4/43ms3132 KiB
11Accepted4/43ms3228 KiB
12Accepted4/43ms3232 KiB
13Accepted4/44ms3268 KiB
14Accepted4/44ms3528 KiB
15Accepted4/437ms4852 KiB
16Accepted4/445ms5428 KiB
17Accepted4/452ms6420 KiB
18Accepted4/459ms6456 KiB
19Accepted4/468ms6944 KiB
20Accepted4/475ms6984 KiB
21Accepted4/475ms6996 KiB
22Accepted4/42ms3944 KiB