116592024-11-04 10:26:07MagyarKendeSZLGFertőzési sorozat (50 pont)cpp17Wrong answer 42/5012ms568 KiB
#include <iostream>
#include <queue>
#include <vector>

using namespace std;

int main() {
    cin.tie(0), ios::sync_with_stdio(0);

    int N, M, K;
    cin >> N >> M >> K;

    vector<int> a(K);
    for (int& x : a) cin >> x;

    vector<vector<int>> g(N + 1);
    while (M--) {
        int U, V;
        cin >> U >> V;
        g[U].push_back(V);
        g[V].push_back(U);
    }

    vector<int> result;
    for (int start = 1; start <= N; start++) {
        vector<int> vis(N + 1);
        vis[start] = 1;
        queue<int> q({start});

        while (!q.empty()) {
            int u = q.front();
            q.pop();
            for (int v : g[u]) {
                if (!vis[v]) {
                    vis[v] = vis[u] + 1;
                    q.push(v);
                }
            }
        }

        vector<int> order(K);
        for (int i = 0; i < K; i++) {
            order[i] = vis[a[i]];
        }

        bool ok = 1;
        for (int i = 1; i < K; i++) {
            int d = order[i] - order[i - 1];
            ok = ok && (d == 0 || d == 1);
        }

        if (ok) result.push_back(start);
    }

    cout << result.size() << "\n";
    for (int x : result) cout << x << " ";
    cout << "\n";
}
SubtaskSumTestVerdictTimeMemory
base42/50
1Accepted0/01ms320 KiB
2Accepted0/01ms320 KiB
3Accepted0/04ms320 KiB
4Accepted2/21ms320 KiB
5Accepted2/22ms320 KiB
6Accepted2/23ms320 KiB
7Accepted2/24ms320 KiB
8Accepted2/24ms320 KiB
9Accepted2/24ms320 KiB
10Accepted2/212ms508 KiB
11Accepted1/12ms376 KiB
12Accepted2/24ms320 KiB
13Accepted2/24ms464 KiB
14Accepted2/23ms320 KiB
15Accepted2/24ms320 KiB
16Accepted2/24ms320 KiB
17Accepted2/23ms320 KiB
18Accepted1/14ms320 KiB
19Accepted1/14ms320 KiB
20Accepted1/13ms500 KiB
21Accepted1/110ms320 KiB
22Accepted1/110ms508 KiB
23Accepted1/18ms320 KiB
24Wrong answer0/18ms472 KiB
25Accepted1/18ms476 KiB
26Accepted1/19ms472 KiB
27Wrong answer0/110ms320 KiB
28Wrong answer0/19ms472 KiB
29Accepted1/110ms472 KiB
30Wrong answer0/18ms472 KiB
31Wrong answer0/18ms472 KiB
32Accepted1/19ms508 KiB
33Accepted1/112ms480 KiB
34Wrong answer0/110ms568 KiB
35Wrong answer0/110ms500 KiB
36Wrong answer0/110ms468 KiB
37Accepted1/110ms468 KiB
38Accepted1/110ms476 KiB
39Accepted1/19ms468 KiB
40Accepted1/110ms320 KiB