201112026-01-01 21:51:24hunzombiFertőzési sorozat (50 pont)cpp17Wrong answer 16/5013ms564 KiB
#include <bits/stdc++.h>
using namespace std;

int n, m, k;
vector<int> ismert;
vector<vector<int>> graph;

bool valid(int root) {
    vector<int> dist(n + 1, -1), days;
    queue<int> q;
    dist[root] = 0;
    q.push(root);

    while (!q.empty()) {
        int sz = q.size();
        int cnt = 0;
        for (int i=0; i < sz; i++) {
            int node = q.front();
            q.pop();
            cnt++;
            for (int next : graph[node]) {
                if (dist[next] == -1) {
                    dist[next] = dist[node] + 1;
                    q.push(next);
                }
            }
        }
        days.push_back(cnt);
    }

    int start = INT_MAX;
    int finish = -1;

    for (int person : ismert) {
        days[dist[person]]--;
        start = min(start, dist[person]);
        finish = max(finish, dist[person]);
    }

    for (int i = start + 1; i < finish; i++) {
        if (days[i] > 0) return false;
    }

    return true;
}

int main() {
    cin >> n >> m >> k;
    ismert.assign(k, 0);
    graph.assign(n + 1, vector<int>());
    for (int i = 0; i < k; i++) {
        cin >> ismert[i];
    }
    for (int i = 0; i < m; i++) {
        int u, v;
        cin >> u >> v;
        graph[u].push_back(v);
        graph[v].push_back(u);
    }

    vector<int> res;
    for (int i=1; i <= n; i++) {
        if (valid(i)) {
            res.push_back(i);
        }
    }

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

    cout << res.size() << '\n';
    for (int num : res) {
        cout << num << ' ';
    }

    return 0;
}
SubtaskSumTestVerdictTimeMemory
base16/50
1Accepted0/01ms316 KiB
2Accepted0/01ms508 KiB
3Wrong answer0/04ms316 KiB
4Wrong answer0/21ms316 KiB
5Wrong answer0/21ms316 KiB
6Wrong answer0/23ms508 KiB
7Wrong answer0/24ms564 KiB
8Wrong answer0/24ms416 KiB
9Wrong answer0/24ms316 KiB
10Wrong answer0/212ms436 KiB
11Wrong answer0/11ms316 KiB
12Accepted2/24ms316 KiB
13Accepted2/26ms316 KiB
14Accepted2/24ms316 KiB
15Accepted2/24ms508 KiB
16Accepted2/27ms500 KiB
17Wrong answer0/24ms316 KiB
18Accepted1/14ms508 KiB
19Accepted1/16ms316 KiB
20Accepted1/14ms348 KiB
21Wrong answer0/112ms316 KiB
22Wrong answer0/112ms436 KiB
23Accepted1/110ms436 KiB
24Wrong answer0/110ms448 KiB
25Wrong answer0/18ms404 KiB
26Wrong answer0/19ms316 KiB
27Wrong answer0/112ms316 KiB
28Wrong answer0/110ms436 KiB
29Accepted1/110ms316 KiB
30Wrong answer0/19ms316 KiB
31Wrong answer0/19ms316 KiB
32Wrong answer0/110ms428 KiB
33Wrong answer0/113ms448 KiB
34Wrong answer0/112ms508 KiB
35Wrong answer0/112ms432 KiB
36Wrong answer0/112ms316 KiB
37Wrong answer0/113ms536 KiB
38Wrong answer0/112ms440 KiB
39Wrong answer0/110ms316 KiB
40Accepted1/112ms316 KiB