71292023-12-31 12:01:38xxxParti (75 pont)cpp17Accepted 75/7532ms6772 KiB
#include <bits/stdc++.h>
using namespace std;

int main() {
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	int n;
	cin >> n;
	vector<pair<int, int> > a(n+1);
	vector<int> b(n+1);
	for(int i = 1; i <= n; i++) {
        int x, y;
        cin >> x >> y;
        b[x]++, b[y]++;
        a[i] = {x, y};
	}

	queue<int> q;

	for(int i = 1; i <= n; i++) {
        if (b[i] < 2) q.push(i);
	}


	while(!q.empty()) {
        int t = q.front();
        q.pop();
        if (b[a[t].first] == 2) {
            b[a[t].first]--;
            q.push(a[t].first);
        } else if (b[a[t].first] > 2) {
            b[a[t].first]--;
        }

        if (b[a[t].second] == 2) {
            b[a[t].second]--;
            q.push(a[t].second);
        } else if (b[a[t].second] > 2) {
            b[a[t].second]--;
        }



	}

    vector<int> ans;

	for(int i = 1; i <= n; i++) if (b[i] > 1) ans.push_back(i);

	cout << ans.size() << '\n';
	for(int x : ans) cout << x << ' ';
	cout << '\n';

	return 0;
}
SubtaskSumTestVerdictTimeMemory
base75/75
1Accepted0/03ms1824 KiB
2Accepted0/017ms3808 KiB
3Accepted3/33ms2128 KiB
4Accepted3/33ms2332 KiB
5Accepted3/33ms2416 KiB
6Accepted3/33ms2644 KiB
7Accepted3/33ms2856 KiB
8Accepted4/43ms2856 KiB
9Accepted4/43ms2856 KiB
10Accepted4/43ms3220 KiB
11Accepted4/43ms3176 KiB
12Accepted4/43ms3196 KiB
13Accepted4/43ms3288 KiB
14Accepted4/44ms3232 KiB
15Accepted4/417ms4992 KiB
16Accepted4/419ms4920 KiB
17Accepted4/423ms5204 KiB
18Accepted4/426ms5476 KiB
19Accepted4/428ms6100 KiB
20Accepted4/430ms6520 KiB
21Accepted4/432ms6772 KiB
22Accepted4/43ms3636 KiB