35672023-03-01 08:10:44gittyHálózati biztonság (50)cpp17Runtime error 22/5032ms64176 KiB
#include <bits/stdc++.h>

using namespace std;

bool **g;

int main()
{

    //ifstream cin("in.txt");

    int n, m, k;
    int torol=1;
    cin >> n >> m >> k;

    vector<int> szamlalo(n + 1, 0);
    vector<int> elod(n + 1, 0);

    g = new bool*[n + 1];

    for(int i = 1; i <= n; i++){
        g[i] = new bool[n + 1];
    }

    for(int i = 1; i <= n; i++){

        for(int j = 0; j <= n; j++){
            g[i][j] = 0;
        }
    }

    for(int i = 1; i <= m; i++){
        int x, y;
        cin >> x >> y;

        g[x][y] = 1;
        g[y][x] = 1;
        szamlalo[x]++;
        szamlalo[y]++;
    }

//    for(int i = 1; i <= n; i++){
//
//        cout << i << ": ";
//        for(int j = 1; j <= n; j++){
//            cout << g[i][j] << " ";
//        }
//
//        cout << "\n";
//    }
//
//    cout << "\n";

    while(torol==1)
    {
        torol = 0;
        for(int i = 1; i <= n; i++){

        if(szamlalo[i] < k && szamlalo[i] > 0){
            torol=1;

            for(int j = 1; j <= n; j++){
                  if(g[i][j]!=0){
                    szamlalo[i]--;
                    g[i][j] = 0;
                }

            }

            for(int j = 1; j <= n; j++){
                if(g[j][i]!=0){
                    szamlalo[j]--;
                    g[j][i] = 0;
                }

            }
        }

    }
    }

//    for(int i = 1; i <= n; i++){
//
//        cout << i << ": ";
//        for(int j = 1; j <= n; j++){
//            cout << g[i][j] << " ";
//        }
//
//        cout << "\n";
//    }


    vector<int> os(n + 1, -1);

    for(int i = 1; i <= n; i++){

        if(szamlalo[i] >= k){

        for(int j = i+1; j <= n; j++){
                if(g[i][j]!=0){

                    if(os[i] == -1){
                        os[i] = i;
                        elod[os[i]]++;
                    }
                    if(os[j]==-1)
                        elod[os[i]]++;

                    os[j] = os[i];
                }
            }
        }
    }

    int ma = 0;
    int ind = 0;

    for(int i = 1; i <= n; i++){

        if(elod[i] >= ma){
            ma = elod[i];
            ind = i;
        }
    }

    int db = 0;

    for(int i = 1; i <= n; i++){
        if(os[i] == ind){
            db++;
        }
    }

    cout << db << "\n";

    for(int i = 1; i <= n; i++){
        if(os[i] == ind){
            cout << i << " ";
        }
    }



    /// rezgraf szamolas es hasonlitas


    return 0;
}
SubtaskSumTestVerdictTimeMemory
base22/50
1Accepted0/03ms1812 KiB
2Runtime error0/028ms64176 KiB
3Accepted2/23ms2228 KiB
4Accepted2/23ms2456 KiB
5Wrong answer0/23ms2816 KiB
6Accepted2/23ms2896 KiB
7Accepted2/23ms3292 KiB
8Accepted2/23ms3284 KiB
9Accepted2/23ms3728 KiB
10Wrong answer0/28ms5688 KiB
11Accepted2/28ms11832 KiB
12Accepted2/229ms21600 KiB
13Accepted3/320ms21564 KiB
14Runtime error0/332ms62960 KiB
15Runtime error0/332ms62788 KiB
16Runtime error0/332ms62640 KiB
17Runtime error0/326ms62800 KiB
18Runtime error0/332ms62196 KiB
19Runtime error0/328ms61544 KiB
20Runtime error0/332ms61324 KiB
21Runtime error0/324ms61292 KiB
22Accepted3/33ms4420 KiB