求助 迷之哇
查看原帖
求助 迷之哇
668288
ce_375楼主2022/10/13 09:30

70pts70pts

#5 #6 #7

#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int n, m, k, q, a[N];
bool v[N], vis[N];
vector<int> vec[N];
bool check(int x, int y){
	if(x == y)return true;
	v[x] = false;
	for(int i = 0; i < vec[x].size(); i++){
		if(v[vec[x][i]] && vec[x][i] != y || vis[vec[x][i]])continue;
		vis[x] = true;
		if(check(vec[x][i], y)){
			vis[x] = false;
			return true;
		}
		vis[x] = false;
	}
	v[x] = true;
	return false;
}
int main(){
	scanf("%d%d%d%d", &n, &m, &k, &q);
	for(int i = 1; i <= m; i++){
		int u, v;
		scanf("%d%d", &u, &v);
		vec[u].push_back(v);
		vec[v].push_back(u);
	}
	while(q--){
		bool f = true;
		memset(a, 0, sizeof(a));
		for(int i = 1; i <= k; i++){
			scanf("%d", a + i);
			v[a[i]] = true;
		}
		for(int i = 2; i <= k; i++){
			if(!check(a[i - 1], a[i])){
				printf("No\n");
				f = false;
				break;
			}
		}
		if(f)printf("Yes\n");
	}
	return 0;
} 
2022/10/13 09:30
加载中...