116602024-11-04 11:41:25MagyarKendeSZLGFertőzési sorozat (50 pont)cpp17Wrong answer 47/5018ms660 KiB
#include <iostream>
#include <queue>
#include <set>
#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;
    set<int> aSet(a.begin(), a.end());

    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);
        set<int> orderSet;
        for (int i = 0; i < K; i++) {
            orderSet.insert(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);
        }

        orderSet.erase(orderSet.begin());
        if (!orderSet.empty()) {
            orderSet.erase(*orderSet.rbegin());
        }

        for (int u = 1; u <= N; u++) {
            ok = ok &&
                 !(!aSet.count(u) && orderSet.count(u));
        }

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

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