96862024-02-26 16:16:29norbertvidaParti (75 pont)cpp11Accepted 75/7539ms12260 KiB
#include <bits/stdc++.h>

using namespace std;

int main() {
    iostream::sync_with_stdio(0);
    cin.tie(0);
    int N;
    cin >> N;
    vector<int> edgesA(N), edgesB(N);
    vector<int> invitee_counter(N, 0);
    for(int i = 0, a, b; i < N; ++i) {
        cin >> edgesA[i] >> edgesB[i];
        --edgesA[i];
        --edgesB[i];
        ++invitee_counter[edgesA[i]];
        ++invitee_counter[edgesB[i]];
    }
    list<int> nodes;
    for(int i = 0; i < N; ++i) nodes.push_back(i);
    bool changes = true;
    while(nodes.size() > 0 && changes) {
        auto it = nodes.begin();
        changes = false;
        while(it != nodes.end()) {
            if(invitee_counter[*it] >= 2) {
                ++it;
                continue;
            }
            changes = true;
            --invitee_counter[edgesA[*it]];
            --invitee_counter[edgesB[*it]];
            auto del_it = it;
            ++it;
            nodes.erase(del_it);
        }
    }
    vector<int> nodes_out;
    nodes_out.reserve(nodes.size());
    for(int x : nodes) nodes_out.push_back(x);
    sort(nodes_out.begin(), nodes_out.end());
    cout << nodes_out.size() << "\n";
    for(auto n : nodes_out) cout << n + 1 << " ";
    cout << "\n";
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base75/75
1Accepted0/03ms2012 KiB
2Accepted0/020ms6520 KiB
3Accepted3/33ms2264 KiB
4Accepted3/33ms2472 KiB
5Accepted3/33ms2600 KiB
6Accepted3/33ms2788 KiB
7Accepted3/33ms2872 KiB
8Accepted4/43ms2892 KiB
9Accepted4/43ms2908 KiB
10Accepted4/43ms2952 KiB
11Accepted4/43ms2904 KiB
12Accepted4/43ms2956 KiB
13Accepted4/44ms3128 KiB
14Accepted4/44ms3252 KiB
15Accepted4/420ms7288 KiB
16Accepted4/424ms8244 KiB
17Accepted4/428ms9136 KiB
18Accepted4/432ms10276 KiB
19Accepted4/435ms10988 KiB
20Accepted4/439ms12260 KiB
21Accepted4/439ms12036 KiB
22Accepted4/43ms3364 KiB