77432024-01-10 21:35:35AblablablaParti (75 pont)cpp17Accepted 75/7590ms15976 KiB
#include <bits/stdc++.h>

using namespace std;

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

    vector<vector<int>> csucsok(n, vector<int>());
    vector<int> befok(n, 0);

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

        csucsok[i].push_back(a);
        csucsok[i].push_back(b);
        befok[a]++;
        befok[b]++;
    }

    queue<int> bejar;
    vector<bool> bejart(n, 0);

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

        bejar.push(i);
    }

    while(!bejar.empty()){
        int akt = bejar.front();
        bejar.pop();


        if(bejart[akt]) continue;

        bejart[akt] = 1;

        for(int x : csucsok[akt]){
            befok[x]--;

            if(befok[x] < 2){
                bejar.push(x);
            }
        }
    }

    int valasz = 0;
    for(int i = 0; i < n; i++){
        valasz += !bejart[i];
    }

    cout << valasz << "\n";
    for(int i = 0; i < n; i++){
        if(!bejart[i]){
            cout << i + 1 << " ";
        }
    }
    cout << "\n";
}
SubtaskSumTestVerdictTimeMemory
base75/75
1Accepted0/03ms1812 KiB
2Accepted0/046ms8032 KiB
3Accepted3/33ms2296 KiB
4Accepted3/33ms2428 KiB
5Accepted3/33ms2516 KiB
6Accepted3/33ms2528 KiB
7Accepted3/33ms2764 KiB
8Accepted4/43ms3144 KiB
9Accepted4/43ms3240 KiB
10Accepted4/44ms3492 KiB
11Accepted4/44ms3588 KiB
12Accepted4/44ms3740 KiB
13Accepted4/44ms3604 KiB
14Accepted4/46ms4048 KiB
15Accepted4/446ms9544 KiB
16Accepted4/454ms10648 KiB
17Accepted4/463ms11872 KiB
18Accepted4/472ms13080 KiB
19Accepted4/481ms14752 KiB
20Accepted4/490ms15812 KiB
21Accepted4/490ms15976 KiB
22Accepted4/43ms3988 KiB