35662023-03-01 08:07:26gittyHálózati biztonság (50)cpp17Runtime error 22/5035ms64188 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;
        }
    }

    cout << ma << "\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/035ms64188 KiB
3Accepted2/23ms2236 KiB
4Accepted2/23ms2464 KiB
5Wrong answer0/23ms2544 KiB
6Accepted2/23ms2676 KiB
7Accepted2/23ms3080 KiB
8Accepted2/23ms3476 KiB
9Accepted2/23ms3760 KiB
10Wrong answer0/28ms5472 KiB
11Accepted2/27ms11492 KiB
12Accepted2/228ms21644 KiB
13Accepted3/319ms21872 KiB
14Runtime error0/325ms62968 KiB
15Runtime error0/321ms62724 KiB
16Runtime error0/323ms62568 KiB
17Runtime error0/326ms62664 KiB
18Runtime error0/332ms61820 KiB
19Runtime error0/327ms61196 KiB
20Runtime error0/332ms61168 KiB
21Runtime error0/328ms60948 KiB
22Accepted3/33ms4820 KiB