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. docker开启加速(第三篇)

    前言:  docker的镜像仓库在国外,下载会很慢,启用阿里云加速. 第一步:cd /etc/docker目录下,打开daemon.json 第二步:修改daemon.json文件,添加阿里云加速: ...

  2. 索引使用,分析初探。(explain分析执行计划,以及强制使用force index)

    促使这次探索的初衷还是因为要对一个定时脚本性能进行优化. 脚本有两个指定状态分别是status, latest_process_status,和一个超期时间expire_time进行限制. 按照我以前 ...

  3. django rest framework批量上传图片及导入字段

    一.项目需求 批量上传图片,然后批量导入(使用excel)每个图片对应的属性(属性共十个,即对应十个字段,其中外键三个). 二.问题 一次可能上传成百上千张图片和对应字段,原来数据库的设计我将图片和对 ...

  4. python设计模式第八天【装饰器模式】

    1.定义 使用包装的释放扩展类的功能,但是不使用继承 2.使用场景 3.代码实现 #!/usr/bin/env python #! _*_ coding:UTF-8 _*_ def MyDecorat ...

  5. python数据结构与算法第十三天【归并排序】

    1.代码实现 def merge_sort(alist): if len(alist) <= 1: return alist # 二分分解 num = len(alist)/2 left = m ...

  6. shiro框架的UsernamePasswordToken与对应Realm中的AuthenticationToken的一点比较

    这里以简单的登陆为例子 控制器对应的登陆方法: @RequestMapping(value = "/login", method = RequestMethod.GET) publ ...

  7. QTP 自动化测试桌面程序--笔记(关闭 启动程序脚本) 、安装

    0 安装qtp .exe 文件 安装 插件文件(如delph) 1 关闭 启动程序: 将要操作的程序-存入localdatatable中 设置 迭代一次 rem SystemUtil.ClosePro ...

  8. 微信小程序支付功能

    API:wx.requestPayment() { } https://blog.csdn.net/qishubiao/article/details/80804052

  9. 安装mysql zip5.7版--安裝

    一直以来都习惯了使用MySQL安装文件(.exe),今天下载了一个.zip版本的MySQL,安装过程中遇到了一些问题,如下: 1.在MySQL官网上(http://dev.mysql.com/down ...

  10. Condition线程通信(七)

    前言:对于线程通信,使用synchronized时使用wait.notify和notifyAll来实行线程通信.而使用Lock如何处理线程通信呢?答案就是本片的主角:Condition. 一.Cond ...