A vertex cover of a graph is a set of vertices such that each edge of the graph is incident to at least one vertex of the set. Now given a graph with several vertex sets, you are supposed to tell if each of them is a vertex cover or not.

Input Specification:

Each input file contains one test case. For each case, the first line gives two positive integers N and M (both no more than 1), being the total numbers of vertices and the edges, respectively. Then M lines follow, each describes an edge by giving the indices (from 0 to N−1) of the two ends of the edge.

After the graph, a positive integer K (≤ 100) is given, which is the number of queries. Then K lines of queries follow, each in the format:

N​v​​ v[1] v[2]⋯v[N​v​​]

where N​v​​ is the number of vertices in the set, and v[i]'s are the indices of the vertices.

Output Specification:

For each query, print in a line Yes if the set is a vertex cover, or No if not.

Sample Input:

10 11
8 7
6 8
4 5
8 4
8 1
1 2
1 4
9 8
9 1
1 0
2 4
5
4 0 3 8 4
6 6 1 7 5 4 9
3 1 8 4
2 2 8
7 9 8 7 6 5 4 2

Sample Output:

No
Yes
Yes
No
No
#include<iostream>
#include<cstdio>
using namespace std;
int N, M, edge1[], edge2[], pt = ;
int hashV[] = {};
int main(){
scanf("%d%d",&N, &M);
for(int i = ; i < M; i++){
scanf("%d%d", &edge1[i], &edge2[i]);
}
int K;
scanf("%d", &K);
for(int i = ; i < K; i++){
int Nv, tag = ;
scanf("%d", &Nv);
fill(hashV, hashV + N, );
for(int j = ; j < Nv; j++){
int vv;
scanf("%d", &vv);
hashV[vv] = ;
}
for(int j = ; j < M; j++){
if(hashV[edge1[j]] == && hashV[edge2[j]] == ){
tag = ;
break;
}
}
if(tag == )
printf("No\n");
else printf("Yes\n");
}
cin >> N;
return ;
}

总结:

1、题意:给出一个图,然后给出一组点的集合,问这组点能否满足:图中任意一条边均包含至少一个集合中的点。

2、属于模拟题,不需要按照往常存储图的方法(邻接表、邻接矩阵)存储,只需要将每一条边存下来方便遍历即可。可按照edge1[N], edge2[N]的方式存储边。遍历时顺序遍历即可。查看点是否存在,可以将集合中的点都存在哈希表中。

 

A1134. Vertex Cover的更多相关文章

  1. PAT A1134 Vertex Cover (25 分)——图遍历

    A vertex cover of a graph is a set of vertices such that each edge of the graph is incident to at le ...

  2. PAT甲级——A1134 Vertex Cover【25】

    A vertex cover of a graph is a set of vertices such that each edge of the graph is incident to at le ...

  3. PAT_A1134#Vertex Cover

    Source: PAT A1134 Vertex Cover (25 分) Description: A vertex cover of a graph is a set of vertices su ...

  4. 集合覆盖 顶点覆盖: set cover和vertex cover

    这里将讲解一下npc问题中set cover和vertex cover分别是什么. set cover: 问题定义: 实例:现在有一个集合A,其中包含了m个元素(注意,集合是无序的,并且包含的元素也是 ...

  5. URAL 2038 Minimum Vertex Cover

    2038. Minimum Vertex Cover Time limit: 1.0 secondMemory limit: 64 MB A vertex cover of a graph is a ...

  6. PAT1134:Vertex Cover

    1134. Vertex Cover (25) 时间限制 600 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue A vertex ...

  7. PAT 甲级 1134 Vertex Cover

    https://pintia.cn/problem-sets/994805342720868352/problems/994805346428633088 A vertex cover of a gr ...

  8. 二分图匹配 + 最小点覆盖 - Vertex Cover

    Vertex Cover Problem's Link Mean: 给你一个无向图,让你给图中的结点染色,使得:每条边的两个顶点至少有一个顶点被染色.求最少的染色顶点数. analyse: 裸的最小点 ...

  9. SCU - 4439 Vertex Cover (图的最小点覆盖集)

    Vertex Cover frog has a graph with \(n\) vertices \(v(1), v(2), \dots, v(n)\) and \(m\) edges \((v(a ...

随机推荐

  1. Angular 自定义过滤器

    <!DOCTYPE html><html ng-app="myApp"><head lang="en"> <meta ...

  2. Angular 自定义指令传参

    <!DOCTYPE html><html ng-app="myApp"><head lang="en"> <meta ...

  3. Oracle调优总结

    Oracle调优总结(经典实践 重要) https://blog.csdn.net/dtjiawenwang88/article/details/74892245 https://www.cnblog ...

  4. Hbase表结构模型

  5. SVN连接不上,Host地址问题

    链接https://svn.ct-ec:8888/svn/189cn-document C:\Windows\System32\drivers\etc 单独换成单行,就好了.

  6. How to install Lion on PC

    open 'InstallESD.dmg' open '/Volumes/Mac OS X Install ESD/BaseSystem.dmg' rm '/Volumes/Mac OS X Base ...

  7. poj-1724(bfs+优先队列)

    题意:有向图,给你m条边,每条边有两个权值,路径长和通过这条路径的花费,问你在不超过k花费的前提下,最短的路径从1走到n 解题思路:因为边数很少,我们可以直接用暴力每条边的方式来找最小的路径长,也就是 ...

  8. linux 目录分类与文件操作

    / 虚拟根目录 一般不会在这里存储文件 /bin 二进制目录,存放需要GNU用户级的工具 /boot 启动目录,存放启动文件 /dev 设备目录,linux在这里创建设备节点 /etc 系统配置文件目 ...

  9. layui laydate设置当前日期往后不可选

    layui laydate设置当前日期往后不可选 laydate.render({ elem: '#demo', max: maxDate() }); // 设置最大可选的日期 function ma ...

  10. 未能写入输出文件“c:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\root\2da42acc\ab2935

    未能写入输出文件“c:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\root\2da42acc\ab293 ...