96772024-02-23 22:14:21Pbg4444Parti (75 pont)cpp17Wrong answer 72/7589ms16336 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) + " ";
        }
    }
    if (ans != "") ans.erase(ans.size()-1);
    cout<<out;
    if(ans != "")cout<<"\n"<<ans;
}

SubtaskSumTestVerdictTimeMemory
base72/75
1Accepted0/03ms1812 KiB
2Accepted0/045ms8748 KiB
3Accepted3/33ms2380 KiB
4Accepted3/33ms2500 KiB
5Wrong answer0/33ms2672 KiB
6Accepted3/33ms2820 KiB
7Accepted3/33ms2892 KiB
8Accepted4/43ms3280 KiB
9Accepted4/43ms3404 KiB
10Accepted4/44ms3444 KiB
11Accepted4/43ms3376 KiB
12Accepted4/44ms3708 KiB
13Accepted4/44ms3920 KiB
14Accepted4/46ms4152 KiB
15Accepted4/445ms9852 KiB
16Accepted4/452ms11412 KiB
17Accepted4/461ms12604 KiB
18Accepted4/470ms13864 KiB
19Accepted4/479ms15084 KiB
20Accepted4/487ms16332 KiB
21Accepted4/489ms16336 KiB
22Accepted4/43ms3600 KiB