96722024-02-23 22:03:50Pbg4444Parti (75 pont)cpp17Wrong answer 72/7593ms22700 KiB
#include <bits/stdc++.h>
using namespace std;

int main() {
    int n;
    cin >> n;

    vector<int> adj[n];
    vector<int> s(n, 0);

    int a, b;
    for (int i = 0; i < n; i++) {
        cin >> a >> b;

        adj[i].push_back(a-1);
        adj[i].push_back(b-1);
        s[a-1]++;
        s[b-1]++;
    }

    queue<int> q;
    vector<bool> v(n, 0);

    for (int i = 0; i < n; i++) {
        if (s[i] >= 2) continue;

        q.push(i);
    }

    while (!q.empty()) {
        int z = q.front();
        q.pop();

        if (v[z]) continue;

        v[z] = 1;

        for (int y : adj[z]) {
            s[y]--;
            if (s[y] < 2) q.push(y);
        }
    }

    int out = 0;
    string ans;
    for(int i = 0; i < n; i++){
        if(!v[i]){
            out++;
            ans += to_string(i+1) + " ";
        }
    }

    cout<<out<<"\n";
    cout<<ans;




    
}

SubtaskSumTestVerdictTimeMemory
base72/75
1Accepted0/03ms1812 KiB
2Accepted0/046ms9120 KiB
3Accepted3/33ms2836 KiB
4Accepted3/33ms3048 KiB
5Wrong answer0/33ms3092 KiB
6Accepted3/33ms3228 KiB
7Accepted3/33ms3344 KiB
8Accepted4/43ms3720 KiB
9Accepted4/43ms3988 KiB
10Accepted4/44ms4244 KiB
11Accepted4/43ms4164 KiB
12Accepted4/44ms4524 KiB
13Accepted4/44ms4916 KiB
14Accepted4/46ms5092 KiB
15Accepted4/446ms11704 KiB
16Accepted4/456ms13984 KiB
17Accepted4/464ms16140 KiB
18Accepted4/474ms18288 KiB
19Accepted4/482ms20592 KiB
20Accepted4/493ms22532 KiB
21Accepted4/493ms22700 KiB
22Accepted4/43ms9836 KiB