156032025-02-21 07:52:44ZsBalazsFertőzési sorozat (50 pont)cpp17Wrong answer 34/5014ms508 KiB
#include <bits/stdc++.h>
using namespace std;

int n, m, k;
vector<int> sorozat;
vector<vector<int>> graph;

vector<int> napok;

bool test(int honnan) {
    napok.assign(n, 0);
    
    queue<pair<int, int>> sor;
    sor.push({honnan, 1});
    
    while (!sor.empty()) {
        int current = sor.front().first;
        int nap = sor.front().second;
        sor.pop();
        
        if (napok[current] != 0) continue;
        
        napok[current] = nap;
        
        for (int szom : graph[current]) {
            sor.push({szom, nap+1});
        }
    }
    
    bool good = true;
    
    int last = napok[sorozat[0]];
    for (int index : sorozat) {
        if (last != napok[index] && last+1 != napok[index]) {
            good = false;
            break;
        }
    }
    
    return good;
}

int main() {
	cin >> n >> m >> k;
	
	graph.resize(n);
	
	for (int i = 0; k > i; i++) {
	    int temp;
	    cin >> temp;
	    
	    sorozat.push_back(temp-1);
	}
	
	for (int i = 0; m > i; i++) {
	    int a, b;
	    cin >> a >> b;
	    
	    a--;
	    b--;
	    
	    graph[a].push_back(b);
	    graph[b].push_back(a);
	}
	
	vector<int> megoldasok;
	
	for (int i = 0; n > i; i++) {
	    if (test(i)) megoldasok.push_back(i);
	}
	
	cout << megoldasok.size() << endl;
	for (int megold : megoldasok) {
	    cout << megold+1 << " ";
	}
	cout << endl;
    
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base34/50
1Accepted0/01ms316 KiB
2Accepted0/01ms316 KiB
3Accepted0/04ms316 KiB
4Accepted2/21ms316 KiB
5Accepted2/22ms316 KiB
6Accepted2/24ms316 KiB
7Accepted2/24ms316 KiB
8Accepted2/24ms508 KiB
9Accepted2/24ms316 KiB
10Accepted2/213ms448 KiB
11Accepted1/12ms316 KiB
12Accepted2/27ms432 KiB
13Accepted2/27ms432 KiB
14Accepted2/26ms316 KiB
15Accepted2/27ms432 KiB
16Accepted2/28ms316 KiB
17Accepted2/26ms316 KiB
18Wrong answer0/17ms508 KiB
19Accepted1/17ms316 KiB
20Accepted1/16ms508 KiB
21Accepted1/114ms316 KiB
22Accepted1/113ms436 KiB
23Wrong answer0/113ms444 KiB
24Wrong answer0/112ms436 KiB
25Wrong answer0/112ms448 KiB
26Wrong answer0/113ms508 KiB
27Wrong answer0/114ms444 KiB
28Wrong answer0/113ms440 KiB
29Accepted1/113ms436 KiB
30Wrong answer0/112ms316 KiB
31Wrong answer0/112ms344 KiB
32Wrong answer0/113ms316 KiB
33Wrong answer0/114ms316 KiB
34Wrong answer0/114ms444 KiB
35Wrong answer0/114ms448 KiB
36Wrong answer0/113ms316 KiB
37Wrong answer0/114ms440 KiB
38Wrong answer0/113ms448 KiB
39Accepted1/113ms444 KiB
40Accepted1/113ms444 KiB