145862025-01-19 14:30:51zsombHálózati biztonság (50)cpp17Time limit exceeded 38/50400ms11436 KiB
#include <bits/stdc++.h>
using namespace std;

struct node
{
    vector<int> order_;
    // unordered_map<int, int> to;
    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];

            (*queue).push_back(nextIdx);

            //(*graph)[currIdx].to[nextIdx] = 0;
            //(*graph)[nextIdx].to[currIdx] = 0;
            (*graph)[currIdx].connCount = 0;
            (*graph)[nextIdx].connCount--;
        }

        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].to[v] = 1;
        // graph[v].to[u] = 1;

        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;

    // sort(end.begin(), end.end());

    for (int i = 0; i < end.size(); i++)
    {
        cout << end[i] << " ";
    }
}
SubtaskSumTestVerdictTimeMemory
base38/50
1Accepted0/01ms316 KiB
2Time limit exceeded0/0381ms7092 KiB
3Accepted2/21ms316 KiB
4Accepted2/21ms316 KiB
5Accepted2/21ms316 KiB
6Accepted2/21ms316 KiB
7Accepted2/21ms316 KiB
8Accepted2/21ms316 KiB
9Accepted2/21ms316 KiB
10Accepted2/26ms572 KiB
11Accepted2/22ms508 KiB
12Accepted2/24ms580 KiB
13Accepted3/32ms316 KiB
14Accepted3/34ms820 KiB
15Accepted3/37ms1332 KiB
16Time limit exceeded0/3400ms5436 KiB
17Accepted3/38ms1332 KiB
18Accepted3/310ms2320 KiB
19Time limit exceeded0/3400ms11436 KiB
20Time limit exceeded0/3400ms10384 KiB
21Time limit exceeded0/3381ms11180 KiB
22Accepted3/31ms316 KiB