147962025-02-02 17:57:33sarminParti (75 pont)cpp17Accepted 75/7537ms4948 KiB
#include <bits/stdc++.h>
using namespace std;

int main() {

	ios_base::sync_with_stdio(0);
	cin.tie(0);

	int n; cin >> n;
	vector<pair<int, int>> v(n);
	vector<int> a(n, 0);
	for (int i = 0; i < n; i++) {
        cin >> v[i].first >> v[i].second;
        v[i].first--; v[i].second--;
        a[v[i].first]++; a[v[i].second]++;
    }

    list<int> living;
    for (int i = 0; i < n; i++) living.push_back(i);
    bool volt = true;
    while (living.size() && volt) {
        volt = false;
        auto i = living.begin();
        while (i != living.end()) {
            if (a[*i] >= 2) {
                i++;
                continue;
            }
            volt = true;
            a[v[*i].first]--; a[v[*i].second]--;
            i = living.erase(i);
        }
    }

    living.sort();
    cout << living.size() << "\n";
    for (int x : living) cout << x+1 << " ";
    cout << "\n";

	return 0;
}
SubtaskSumTestVerdictTimeMemory
base75/75
1Accepted0/01ms316 KiB
2Accepted0/019ms2560 KiB
3Accepted3/31ms316 KiB
4Accepted3/31ms508 KiB
5Accepted3/31ms316 KiB
6Accepted3/31ms316 KiB
7Accepted3/31ms316 KiB
8Accepted4/41ms500 KiB
9Accepted4/41ms316 KiB
10Accepted4/42ms320 KiB
11Accepted4/41ms316 KiB
12Accepted4/42ms408 KiB
13Accepted4/42ms328 KiB
14Accepted4/42ms564 KiB
15Accepted4/418ms2560 KiB
16Accepted4/423ms2936 KiB
17Accepted4/427ms3568 KiB
18Accepted4/429ms4008 KiB
19Accepted4/434ms4404 KiB
20Accepted4/437ms4948 KiB
21Accepted4/437ms4732 KiB
22Accepted4/41ms388 KiB