241922026-02-05 22:55:13lorantbFertőzési sorozat (50 pont)cpp17Wrong answer 24/5014ms584 KiB
#include <bits/stdc++.h>
using namespace std;
vector<vector<int>> g;

void bfs(int a, vector<int> &x) {
	queue<int> q;
	q.push(a);
	x[a] = 0;
	while(q.size() != 0) {
		int v = q.front();
		q.pop();
		for(int i : g[v]) {
			if(x[i] == -1) {
				x[i] = x[v] + 1;
				q.push(i);
			}
		}
	}
}

int main() {
	int n,m,k; cin >> n >> m >> k;
	vector<int> x(0);
	g.assign(n+1, vector<int>(0));
	vector<int> ans(0);
	for(int i = 0; i < k; i++) {
		int a; cin >> a;
		x.push_back(a);
	}
	for(int i = 0; i < m; i++) {
		int a,b; cin >>a >> b;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	for(int i = 1; i <= n; i++) {
		vector<int> z(n+1, -1);
		bfs(i,z);
		bool u = true;
		for(int j = 1; j < k; j++) {
			if(z[x[j]] != z[x[j-1]] && (z[x[j]] != z[x[j-1]] + 1 && z[x[j]] != 0)) u = false;
		}
		if(u) ans.push_back(i);
	}
	cout << ans.size() << endl;
	for(int i : ans) cout << i << " ";
}
SubtaskSumTestVerdictTimeMemory
base24/50
1Wrong answer0/01ms316 KiB
2Wrong answer0/01ms316 KiB
3Wrong answer0/04ms508 KiB
4Wrong answer0/21ms316 KiB
5Wrong answer0/22ms316 KiB
6Wrong answer0/24ms316 KiB
7Wrong answer0/23ms316 KiB
8Wrong answer0/23ms316 KiB
9Wrong answer0/24ms424 KiB
10Wrong answer0/212ms432 KiB
11Wrong answer0/11ms316 KiB
12Wrong answer0/24ms508 KiB
13Accepted2/24ms316 KiB
14Accepted2/24ms316 KiB
15Accepted2/24ms316 KiB
16Accepted2/24ms316 KiB
17Accepted2/24ms432 KiB
18Accepted1/14ms420 KiB
19Accepted1/14ms316 KiB
20Wrong answer0/14ms316 KiB
21Accepted1/112ms440 KiB
22Accepted1/110ms432 KiB
23Accepted1/19ms584 KiB
24Wrong answer0/18ms316 KiB
25Accepted1/18ms316 KiB
26Accepted1/19ms316 KiB
27Wrong answer0/110ms316 KiB
28Wrong answer0/18ms316 KiB
29Accepted1/112ms560 KiB
30Wrong answer0/18ms440 KiB
31Wrong answer0/18ms352 KiB
32Accepted1/19ms508 KiB
33Accepted1/114ms444 KiB
34Wrong answer0/112ms316 KiB
35Wrong answer0/110ms316 KiB
36Wrong answer0/110ms316 KiB
37Accepted1/112ms500 KiB
38Accepted1/112ms508 KiB
39Accepted1/110ms316 KiB
40Accepted1/113ms316 KiB