93262024-02-20 14:14:36AblablablaHálózati biztonság (50)cpp17Wrong answer 37/50150ms27104 KiB
#include <bits/stdc++.h>

using namespace std;

vector<vector<int>> csucsok;

int main()
{
    int n, m, k;
    cin >> n >> m >> k;

    vector<int> befok(n);
    csucsok.assign(n, vector<int>());
    for(int i = 0; i < m; i++){
        int a, b;
        cin >> a >> b;
        a--; b--;

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

    vector<vector<int>> uj(n, vector<int>());
    vector<bool> benne(n, 1);
    for(int i = 0; i < n; i++){
        if(befok[i] < k){
            benne[i] = 0;
            continue;
        }

        for(int x : csucsok[i]){
            if(befok[x] < k) continue;

            uj[i].push_back(x);
        }
    }

    queue<int> bejar;

    for(int i = 0; i < n; i++){
        befok[i] = uj[i].size();

        if(befok[i] != 0 && befok[i] < k){
            bejar.push(i);
        }
    }

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

        if(!benne[akt]) continue;

        benne[akt] = 0;

        for(int x : uj[akt]){
            if(!benne[x]) continue;

            befok[x]--;

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

    vector<int> megoldas;
    for(int i = 0; i < n; i++){
        if(benne[i]){
            megoldas.push_back(i);
        }
    }

    cout << megoldas.size() << "\n";
    for(int x : megoldas){
        cout << x + 1 << " ";
    }
    cout << "\n";
}
SubtaskSumTestVerdictTimeMemory
base37/50
1Accepted0/03ms1812 KiB
2Accepted0/082ms12044 KiB
3Accepted2/23ms3472 KiB
4Accepted2/23ms3692 KiB
5Accepted2/23ms3920 KiB
6Wrong answer0/23ms4128 KiB
7Accepted2/23ms4244 KiB
8Accepted2/23ms4460 KiB
9Wrong answer0/23ms4576 KiB
10Accepted2/28ms5344 KiB
11Accepted2/24ms5116 KiB
12Accepted2/27ms5512 KiB
13Accepted3/33ms5316 KiB
14Accepted3/37ms6364 KiB
15Accepted3/38ms7676 KiB
16Wrong answer0/379ms12716 KiB
17Wrong answer0/38ms7248 KiB
18Accepted3/313ms12080 KiB
19Wrong answer0/386ms23100 KiB
20Accepted3/3150ms26832 KiB
21Accepted3/396ms27104 KiB
22Accepted3/33ms11008 KiB