PAT--1134 Vertex Cover

Topic links: https://pintia.cn/problem-sets/994805342720868352/problems/994805346428633088

Title effect: given an undirected graph, and then given a set of k sets of points, each set point Q set to each edge can include (as long as one edge of a vertex included in the set which even).

Analysis: For each group set, each traversed a side, a long side of a two vertices in the set which are not, then this edge is not necessarily included.

#include <bits/stdc++.h>
using namespace std;
const int N = 1e4 + 5;
int n, m, k, cnt, a[N];
bool vis[N];
struct Edge {
	int a, b;
}edge[2 * N];
void add(int x, int y) {
	edge[cnt].a = x;
	edge[cnt].b = y;
	cnt++;
}
bool check() {
	int x, y;
	for(int i = 0; i < cnt; i++) {
		x = edge[i].a;
		y = edge[i].b;
		if(!vis[x] && !vis[y]) return false;
	}
	return true;
}
int main() {
	cnt = 0;
	scanf("%d %d", &n, &m);
	int x, y;
	for(int i = 0; i < m; i++) {
		scanf("%d %d", &x, &y);
		add(x, y);
		add(y, x);
	}
	scanf("%d", &k);
	int num;
	while(k--) {
		memset(vis, 0, sizeof vis);
		scanf("%d", &num);
		for(int i = 1; i <= num; i++) {
			scanf("%d", &a[i]);
			vis[a[i]] = 1;
		}
		if(check()) printf("Yes\n");
		else printf("No\n");
	}
	return 0;
}

 

Published 150 original articles · won praise 4 · Views 6930

Guess you like

Origin blog.csdn.net/Napom/article/details/103299065