201122026-01-01 21:57:05hunzombiFertőzési sorozat (50 pont)cpp17Wrong answer 1/5013ms632 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_cnt;
    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_cnt.push_back(cnt);
    }

    int start = INT_MAX;
    int finish = -1;

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

    for (int i=1; i < ismert.size(); i++) {
        if (dist[i - 1] > dist[i]) return false;
    }

    for (int i = start + 1; i < finish; i++) {
        if (days_cnt[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
base1/50
1Accepted0/01ms508 KiB
2Accepted0/01ms500 KiB
3Wrong answer0/04ms316 KiB
4Wrong answer0/21ms316 KiB
5Wrong answer0/21ms316 KiB
6Wrong answer0/23ms316 KiB
7Wrong answer0/24ms316 KiB
8Wrong answer0/24ms316 KiB
9Wrong answer0/24ms316 KiB
10Wrong answer0/212ms316 KiB
11Wrong answer0/12ms316 KiB
12Wrong answer0/24ms556 KiB
13Wrong answer0/27ms316 KiB
14Wrong answer0/24ms316 KiB
15Wrong answer0/24ms316 KiB
16Wrong answer0/26ms428 KiB
17Wrong answer0/24ms316 KiB
18Wrong answer0/14ms508 KiB
19Wrong answer0/16ms436 KiB
20Wrong answer0/14ms316 KiB
21Wrong answer0/112ms508 KiB
22Wrong answer0/112ms436 KiB
23Wrong answer0/110ms620 KiB
24Wrong answer0/19ms508 KiB
25Wrong answer0/18ms316 KiB
26Wrong answer0/110ms396 KiB
27Wrong answer0/112ms440 KiB
28Wrong answer0/19ms432 KiB
29Wrong answer0/112ms444 KiB
30Wrong answer0/19ms316 KiB
31Wrong answer0/19ms316 KiB
32Wrong answer0/110ms436 KiB
33Wrong answer0/113ms508 KiB
34Wrong answer0/113ms632 KiB
35Wrong answer0/112ms432 KiB
36Wrong answer0/112ms432 KiB
37Wrong answer0/112ms316 KiB
38Wrong answer0/112ms432 KiB
39Accepted1/110ms316 KiB
40Wrong answer0/112ms432 KiB