166612025-05-07 19:39:37sztomiFertőzési sorozat (50 pont)cpp17Wrong answer 47/5013ms628 KiB
#include <bits/stdc++.h>

using namespace std;

int n;
vector<int> felosztas; // bad practice
vector<vector<int>> graf;
vector<int> volt;
vector<int> sor;
vector<int> kell;
int akt_volt = 1;

bool jo_felosztas(){
    int akt_max = felosztas[sor[0]];
    bool kezdo = true;
    for(int i = 0; i < sor.size(); i++){
        if(felosztas[sor[i]] < akt_max || felosztas[sor[i]]-akt_max > 1){
            return false;
        }
        // ugy valt, hogy meg nem vegzett minden elotte levovel
        if(felosztas[sor[i]]-akt_max == 1){
            if(kezdo){
                kezdo = false;
            }
            else{
                if((kell[akt_max] && !kezdo)){
                    return false;
                }
            }
        }


        akt_max = max(felosztas[sor[i]], akt_max);
        kell[akt_max]--;
    }
    return true;
}

void bfs(int kezd){
    kell.assign(n, 0);
    queue<int> q;
    q.push(kezd);
    volt[kezd] = akt_volt;
    felosztas[kezd] = 0;
    kell[0] = 1;
    int akt;
    while(!q.empty()){
        akt = q.front();
        //cout << "akt: " <<akt << " lepes: " << lepes << "\n";
        q.pop();

        for(auto x : graf[akt]){
            if(volt[x] == akt_volt){
                continue;
            }
            felosztas[x] = felosztas[akt] + 1;
            kell[felosztas[x]]++;
            volt[x] = akt_volt;
            q.push(x);
        }
    }

    int sz = 0;
    for(int i = 0; i < n; i++){
        if(kell[i] == 0) break;
        sz += kell[i];
        kell[i] = sz;
    }


    akt_volt++;
}


int main()
{
    int m, k;
    cin >> n >> m >> k;
    sor.resize(k);
    for(auto &x : sor){
        cin >> x;
        x--;
    }

    graf.assign(n, vector<int>());

    volt.assign(n, 0);
    int a, b;
    for(int i = 0; i < m; i++){
        cin >> a >> b;
        a--;
        b--;
        graf[a].push_back(b);
        graf[b].push_back(a);
    }


    vector<int> jok;
    felosztas.assign(n, -1);
    for(int i = 0; i < n; i++){
        bfs(i);
        /*
        for(int j = 0; j < n; j++){
            cout << felosztas[j] << " ";
        }
        cout << "\n";
        */
        if(jo_felosztas()){
            //cout << "jo felosztas\n";
            jok.push_back(i+1);
        }
    }

    cout << jok.size() << "\n";
    for(auto x : jok){
        cout << x << " ";
    }
    cout << "\n";

}
SubtaskSumTestVerdictTimeMemory
base47/50
1Accepted0/01ms316 KiB
2Accepted0/01ms316 KiB
3Accepted0/04ms316 KiB
4Accepted2/21ms316 KiB
5Accepted2/22ms508 KiB
6Accepted2/24ms316 KiB
7Accepted2/24ms316 KiB
8Accepted2/24ms508 KiB
9Accepted2/24ms500 KiB
10Accepted2/212ms368 KiB
11Accepted1/12ms316 KiB
12Accepted2/24ms508 KiB
13Accepted2/26ms316 KiB
14Accepted2/24ms316 KiB
15Accepted2/24ms436 KiB
16Accepted2/26ms316 KiB
17Accepted2/24ms436 KiB
18Wrong answer0/14ms500 KiB
19Accepted1/16ms600 KiB
20Accepted1/14ms316 KiB
21Accepted1/112ms440 KiB
22Accepted1/112ms440 KiB
23Wrong answer0/19ms440 KiB
24Accepted1/19ms316 KiB
25Accepted1/18ms316 KiB
26Accepted1/110ms384 KiB
27Accepted1/112ms532 KiB
28Accepted1/110ms440 KiB
29Accepted1/112ms448 KiB
30Accepted1/19ms440 KiB
31Accepted1/19ms440 KiB
32Accepted1/110ms444 KiB
33Wrong answer0/113ms508 KiB
34Accepted1/113ms316 KiB
35Accepted1/112ms316 KiB
36Accepted1/112ms316 KiB
37Accepted1/112ms444 KiB
38Accepted1/112ms440 KiB
39Accepted1/110ms628 KiB
40Accepted1/112ms436 KiB