96842024-02-26 15:12:02norbertvidaParti (75 pont)cpp17Time limit exceeded 72/75347ms16656 KiB
#include <bits/stdc++.h>

using namespace std;

int main() {
    iostream::sync_with_stdio(0);
    cin.tie(0);
    int N;
    cin >> N;
    vector<vector<int>> edges(N, vector<int>());
    vector<int> invitee_counter(N, 0);
    for(int i = 0, a, b; i < N; ++i) {
        cin >> a >> b;
        --a;
        --b;
        edges[i].push_back(a);
        edges[i].push_back(b);
        ++invitee_counter[a];
        ++invitee_counter[b];
    }
    vector<int> nodes(N);
    for(int i = 0; i < N; i++) nodes[i] = i;
    while(true) {
        sort(nodes.begin(), nodes.end(), [&](int a, int b) {
            if(invitee_counter[a] == invitee_counter[b]) return a > b;
            return invitee_counter[a] > invitee_counter[b];
        });
        if(invitee_counter[*nodes.rbegin()] >= 2) break;
        for(auto it = nodes.rbegin(); it != nodes.rend(); ++it) {
            if(invitee_counter[*it] >= 2) break;
            for(int n : edges[*it]) --invitee_counter[n];
            nodes.pop_back();
        }
    }
    cout << nodes.size() << "\n";
    for(auto it = nodes.rbegin(); it != nodes.rend(); ++it) cout << (*it) + 1 << " ";
    cout << "\n";
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base72/75
1Accepted0/03ms1832 KiB
2Accepted0/039ms8268 KiB
3Accepted3/33ms2372 KiB
4Accepted3/33ms2332 KiB
5Time limit exceeded0/3347ms2308 KiB
6Accepted3/33ms2476 KiB
7Accepted3/33ms2556 KiB
8Accepted4/43ms2836 KiB
9Accepted4/43ms3076 KiB
10Accepted4/44ms3228 KiB
11Accepted4/43ms3284 KiB
12Accepted4/44ms3572 KiB
13Accepted4/44ms3860 KiB
14Accepted4/44ms4148 KiB
15Accepted4/439ms9868 KiB
16Accepted4/446ms11292 KiB
17Accepted4/452ms12596 KiB
18Accepted4/461ms13728 KiB
19Accepted4/468ms15356 KiB
20Accepted4/479ms16456 KiB
21Accepted4/479ms16656 KiB
22Accepted4/43ms4496 KiB