25052023-01-14 19:55:19JMMirkoParti (75 pont)cpp17Wrong answer 72/7575ms7356 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 << ' ';
}
SubtaskSumTestVerdictTimeMemory
base72/75
1Accepted0/03ms1812 KiB
2Accepted0/037ms3760 KiB
3Accepted3/32ms2260 KiB
4Accepted3/32ms2460 KiB
5Wrong answer0/32ms2496 KiB
6Accepted3/32ms2620 KiB
7Accepted3/32ms2872 KiB
8Accepted4/42ms3076 KiB
9Accepted4/43ms3164 KiB
10Accepted4/43ms3304 KiB
11Accepted4/43ms3380 KiB
12Accepted4/43ms3388 KiB
13Accepted4/44ms3752 KiB
14Accepted4/44ms3704 KiB
15Accepted4/437ms5036 KiB
16Accepted4/445ms5504 KiB
17Accepted4/452ms6380 KiB
18Accepted4/459ms6680 KiB
19Accepted4/465ms6932 KiB
20Accepted4/475ms7068 KiB
21Accepted4/474ms7356 KiB
22Accepted4/42ms4124 KiB