241872026-02-05 22:42:00lorantbFertőzési sorozat (50 pont)cpp17Wrong answer 0/5014ms564 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 < m; 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) u = false;
			if(u) ans.push_back(i);
		}
	}
	cout << ans.size() << endl;
	for(int i : ans) cout << i << " ";
}
SubtaskSumTestVerdictTimeMemory
base0/50
1Accepted0/01ms316 KiB
2Wrong answer0/01ms512 KiB
3Wrong answer0/03ms316 KiB
4Wrong answer0/21ms316 KiB
5Wrong answer0/22ms316 KiB
6Wrong answer0/22ms428 KiB
7Wrong answer0/21ms316 KiB
8Wrong answer0/23ms316 KiB
9Wrong answer0/24ms316 KiB
10Wrong answer0/28ms316 KiB
11Wrong answer0/12ms344 KiB
12Wrong answer0/21ms316 KiB
13Wrong answer0/22ms540 KiB
14Wrong answer0/22ms316 KiB
15Wrong answer0/22ms316 KiB
16Wrong answer0/22ms316 KiB
17Wrong answer0/22ms392 KiB
18Wrong answer0/12ms352 KiB
19Wrong answer0/12ms316 KiB
20Wrong answer0/12ms316 KiB
21Wrong answer0/18ms468 KiB
22Wrong answer0/18ms468 KiB
23Wrong answer0/14ms544 KiB
24Wrong answer0/14ms564 KiB
25Wrong answer0/16ms352 KiB
26Wrong answer0/18ms516 KiB
27Wrong answer0/18ms436 KiB
28Wrong answer0/13ms316 KiB
29Wrong answer0/14ms316 KiB
30Wrong answer0/17ms424 KiB
31Wrong answer0/17ms316 KiB
32Wrong answer0/17ms472 KiB
33Wrong answer0/114ms500 KiB
34Wrong answer0/18ms440 KiB
35Wrong answer0/18ms436 KiB
36Wrong answer0/18ms436 KiB
37Wrong answer0/18ms440 KiB
38Wrong answer0/18ms452 KiB
39Wrong answer0/14ms564 KiB
40Wrong answer0/112ms468 KiB