90282024-02-12 11:59:26IgnácParti (75 pont)cpp17Wrong answer 72/7571ms7184 KiB
// Source: https://usaco.guide/general/io

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

int main() {
	int n;
	cin >> n;
	if (n < 3) {
		cout << 0;
		return 0;
	}
	vector<int> db(n + 1);
	vector<pair<int, int>> to(n + 1);
	for (int i = 1; i <= n; i++) {
		int a, b;
		cin >> a >> b;
		db[a]++;
		db[b]++;
		to[i].first = a;
		to[i].second = b;
	}

	queue<int> out;
	for (int i = 1; i <= n; i++) {
		if (db[i] < 2) {
			out.push(i);
			db[i] = -1;
		}
	}

	while (out.size() > 0) {
		//cout << out.front() << "\n";
		db[to[out.front()].first]--;
		db[to[out.front()].second]--;
		if (db[to[out.front()].first] < 2 && db[to[out.front()].first] > -1) {
			out.push(to[out.front()].first);
			db[to[out.front()].first] = -1;
		}
		if (db[to[out.front()].second] < 2 && db[to[out.front()].second] > -1) {
			out.push(to[out.front()].second);
			db[to[out.front()].second] = -1;
		}
		out.pop();
	}

	string ans;
	int cnt = 0;
	for (int i = 1; i <= n; i++) {
		if (db[i] >= 2) {
			ans += to_string(i) + " ";
			cnt++;
		}
	}

	cout << cnt << "\n" << ans;
}
SubtaskSumTestVerdictTimeMemory
base72/75
1Accepted0/03ms1812 KiB
2Accepted0/037ms3928 KiB
3Accepted3/33ms2280 KiB
4Accepted3/33ms2488 KiB
5Wrong answer0/33ms2776 KiB
6Accepted3/33ms2840 KiB
7Accepted3/33ms2876 KiB
8Accepted4/43ms2884 KiB
9Accepted4/43ms2992 KiB
10Accepted4/44ms3092 KiB
11Accepted4/43ms3100 KiB
12Accepted4/44ms3324 KiB
13Accepted4/44ms3428 KiB
14Accepted4/44ms3512 KiB
15Accepted4/437ms5096 KiB
16Accepted4/448ms5968 KiB
17Accepted4/450ms6316 KiB
18Accepted4/457ms6388 KiB
19Accepted4/471ms6872 KiB
20Accepted4/471ms7140 KiB
21Accepted4/471ms7184 KiB
22Accepted4/43ms4088 KiB