71122023-12-30 17:14:39tomi7Parti (75 pont)cpp17Wrong answer 72/7575ms7208 KiB
// Source: https://usaco.guide/general/io

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

vector<int> azaz;
	vector<pair<int, int>> a;
int ezazooooyeah(int n){
	bool b=false;
	for(int i=0;i<n;i++){
		if(azaz[i]==1 || azaz[i]==0){
		//	cout << i << endl;
			azaz[a[i].first-1]--;
			azaz[a[i].second-1]--;
			azaz[i]=-1;
			b=true;
		/*	for(int ii=0;ii<n;ii++){
				cout<< azaz[ii]<<' ';
				cout<<a[i].first<<' '<<a[i].second<<'\n';
			}
			cout << endl;*/
		}
	}
	if(b){
	return ezazooooyeah(n);
	}
	int valasz=0;
	for(int i=0;i<n;i++){
		if(azaz[i]>=2){
			valasz++;
		}
	}
	return valasz;
}

int main() {
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		pair<int, int> x;
		cin>>x.first>>x.second;
		a.push_back(x);
		azaz.push_back(0);
	}
	for(int i=0;i<n;i++){
		azaz[a[i].first-1]++;
		azaz[a[i].second-1]++;
	}
	bool b=true;
	cout<<ezazooooyeah(n)<<'\n';
	for(int i=0;i<n;i++){
		if(azaz[i]>=2){
			cout<<i+1<<' ';
			b=false;
		}
	}
	if(b){
		cout<<-1;
	}
}
SubtaskSumTestVerdictTimeMemory
base72/75
1Accepted0/03ms1876 KiB
2Accepted0/037ms3700 KiB
3Accepted3/33ms2280 KiB
4Accepted3/33ms2492 KiB
5Wrong answer0/33ms2600 KiB
6Accepted3/33ms2680 KiB
7Accepted3/33ms2680 KiB
8Accepted4/43ms2812 KiB
9Accepted4/43ms2904 KiB
10Accepted4/44ms3016 KiB
11Accepted4/43ms2900 KiB
12Accepted4/44ms3044 KiB
13Accepted4/44ms3428 KiB
14Accepted4/44ms3380 KiB
15Accepted4/437ms5084 KiB
16Accepted4/445ms5164 KiB
17Accepted4/452ms6360 KiB
18Accepted4/459ms6488 KiB
19Accepted4/467ms7132 KiB
20Accepted4/475ms7208 KiB
21Accepted4/474ms7136 KiB
22Accepted4/43ms4084 KiB