145902025-01-19 15:00:55zsombHálózati biztonság (50)cpp17Időlimit túllépés 44/50400ms11572 KiB
#include <bits/stdc++.h>
using namespace std;

struct node
{
    vector<int> order_;

    int in = 1;
    int connCount = 0;
};

void halfBFS(vector<node> *graph, int currIdx, vector<int> *queue, int k)
{
    if ((*graph)[currIdx].connCount < k && (*graph)[currIdx].in != 0)
    {
        (*graph)[currIdx].in = 0;

        for (int i = 0; i < (*graph)[currIdx].order_.size(); i++)
        {
            int nextIdx = (*graph)[currIdx].order_[i];

            (*graph)[currIdx].connCount = 0;
            (*graph)[nextIdx].connCount--;
            if ((*graph)[nextIdx].connCount < k && (*graph)[nextIdx].in != 0)
            {
                (*queue).push_back(nextIdx);
            }
        }

        while ((*queue).size() != 0)
        {
            int d = (*queue)[0];
            (*queue).erase((*queue).begin());
            if ((*graph)[d].connCount < k && (*graph)[d].in != 0)
                halfBFS(graph, d, queue, k);
        }
    }
}

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

    vector<node> graph(n + 1);
    graph[0].in = 0;
    for (int i = 0; i < m; i++)
    {
        int u, v;
        cin >> u >> v;

        graph[u].order_.push_back(v);
        graph[v].order_.push_back(u);

        graph[u].connCount++;
        graph[v].connCount++;
    }
    vector<int> q(0);

    for (int i = 1; i < n + 1; i++)
    {
        if (graph[i].connCount < k)
            halfBFS(&graph, i, &q, k);
    }

    int ossz = 0;
    vector<int> end(0);
    for (int i = 1; i < n + 1; i++)
    {
        if (graph[i].in == 1)
        {
            ossz++;
            end.push_back(i);
        }
    }
    cout << ossz << endl;

    for (int i = 0; i < end.size(); i++)
    {
        cout << end[i] << " ";
    }
}
RészfeladatÖsszpontTesztVerdiktIdőMemória
base44/50
1Elfogadva0/01ms508 KiB
2Időlimit túllépés0/0381ms6952 KiB
3Elfogadva2/21ms316 KiB
4Elfogadva2/21ms316 KiB
5Elfogadva2/21ms316 KiB
6Elfogadva2/21ms500 KiB
7Elfogadva2/21ms316 KiB
8Elfogadva2/21ms316 KiB
9Elfogadva2/21ms388 KiB
10Elfogadva2/26ms564 KiB
11Elfogadva2/22ms316 KiB
12Elfogadva2/24ms564 KiB
13Elfogadva3/31ms316 KiB
14Elfogadva3/36ms840 KiB
15Elfogadva3/37ms1336 KiB
16Időlimit túllépés0/3400ms5168 KiB
17Elfogadva3/37ms984 KiB
18Elfogadva3/39ms2100 KiB
19Elfogadva3/3233ms11304 KiB
20Időlimit túllépés0/3400ms10168 KiB
21Elfogadva3/3236ms11572 KiB
22Elfogadva3/31ms316 KiB