156282025-02-21 11:21:51linhnkFertőzési sorozat (50 pont)cpp17Wrong answer 1/5014ms548 KiB
#include <iostream>
#include <bits/stdc++.h>
#include<queue>

using namespace std;

int main()
{
    int n, m, k, a, b;
    cin>>n>>m>>k;
    vector<int> hal(k);
    vector<vector<int>> cs(n+1);
    vector<int> erdos(n+1, -1);
    vector<bool> alap(n+1, false);
    vector<bool> been(n+1, false);
    queue<int> q;
    vector<int> d;
    bool jaj=true;
    for(int i=0; i<k; i++){
        cin>>hal[i];
        alap[hal[i]]=true;
    }
    alap[hal[0]]=false;
    for(int i=0; i<m; i++){
        cin>>a>>b;
        cs[a].push_back(b);
        cs[b].push_back(a);
    }
    for(int h=1; h<n+1; h++){
            if(alap[h])
                continue;
            jaj=true;
            erdos.assign(n+1, -1);
            been.assign(n+1, false);
            //cout<<h<<endl;
            erdos[h]=0;
            q.push(h);
            /*been[h]=true;
            for(auto x:cs[h]){
                q.push(x);
                erdos[x]=1;
                //cout<<x<<"";
            }*/
            //cout<<endl;
            while(q.size()>0){
                if(!been[q.front()]){
                        been[q.front()]=true;
                    for(auto x:cs[q.front()]){
                        if(erdos[x]==-1){
                            erdos[x]=erdos[q.front()]+1;
                            q.push(x);
                            //cout<<q.front()<<" "<<x<<endl;
                        }
                    }
                }
                q.pop();
            }
            for(int i=0; i<k-1; i++){
                if(erdos[hal[i]]+1<erdos[hal[i+1]]){
                    jaj=false;
                    break;
                }
            }

            if(!jaj){
                    continue;
                }
            for(auto x:erdos){
                    if(x!=-1){
                if(!alap[x]&&x<erdos[hal.back()]&&x>=erdos[hal[0]]){
                    jaj=false;
                    break;

                }
                }
            }
            if(jaj){
                d.push_back(h);
            }
    }
    cout<<d.size()<<endl;
    for(auto x:d){
        cout<<x<<" ";
    }
    /*cout<<endl<<erdos.size()<<endl;
    for(auto x:erdos){
        cout<<x<<" ";
    }*/

}
SubtaskSumTestVerdictTimeMemory
base1/50
1Wrong answer0/01ms316 KiB
2Wrong answer0/01ms508 KiB
3Wrong answer0/04ms316 KiB
4Wrong answer0/21ms316 KiB
5Wrong answer0/22ms316 KiB
6Wrong answer0/24ms316 KiB
7Wrong answer0/24ms316 KiB
8Wrong answer0/24ms316 KiB
9Wrong answer0/24ms316 KiB
10Wrong answer0/214ms432 KiB
11Wrong answer0/11ms404 KiB
12Wrong answer0/28ms548 KiB
13Wrong answer0/28ms316 KiB
14Wrong answer0/26ms400 KiB
15Wrong answer0/27ms316 KiB
16Wrong answer0/27ms432 KiB
17Wrong answer0/26ms316 KiB
18Wrong answer0/14ms436 KiB
19Wrong answer0/17ms508 KiB
20Wrong answer0/16ms436 KiB
21Wrong answer0/110ms432 KiB
22Wrong answer0/110ms508 KiB
23Wrong answer0/18ms436 KiB
24Wrong answer0/18ms508 KiB
25Wrong answer0/19ms440 KiB
26Wrong answer0/19ms436 KiB
27Wrong answer0/113ms508 KiB
28Wrong answer0/110ms316 KiB
29Wrong answer0/112ms436 KiB
30Wrong answer0/110ms544 KiB
31Wrong answer0/19ms436 KiB
32Wrong answer0/110ms444 KiB
33Wrong answer0/12ms316 KiB
34Wrong answer0/114ms436 KiB
35Wrong answer0/114ms432 KiB
36Wrong answer0/113ms432 KiB
37Wrong answer0/112ms436 KiB
38Wrong answer0/112ms432 KiB
39Wrong answer0/19ms436 KiB
40Accepted1/17ms436 KiB