A1134. Vertex Cover
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:
Nv v[1] v[2]⋯v[Nv]
where Nv 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的更多相关文章
- 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 ...
- 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 ...
- PAT_A1134#Vertex Cover
Source: PAT A1134 Vertex Cover (25 分) Description: A vertex cover of a graph is a set of vertices su ...
- 集合覆盖 顶点覆盖: set cover和vertex cover
这里将讲解一下npc问题中set cover和vertex cover分别是什么. set cover: 问题定义: 实例:现在有一个集合A,其中包含了m个元素(注意,集合是无序的,并且包含的元素也是 ...
- 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 ...
- PAT1134:Vertex Cover
1134. Vertex Cover (25) 时间限制 600 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue A vertex ...
- PAT 甲级 1134 Vertex Cover
https://pintia.cn/problem-sets/994805342720868352/problems/994805346428633088 A vertex cover of a gr ...
- 二分图匹配 + 最小点覆盖 - Vertex Cover
Vertex Cover Problem's Link Mean: 给你一个无向图,让你给图中的结点染色,使得:每条边的两个顶点至少有一个顶点被染色.求最少的染色顶点数. analyse: 裸的最小点 ...
- 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 ...
随机推荐
- zookeeper的安装和启动教程
zookeeper的安装和启动 zookeeper安装包所在目录: 上传文件到虚拟机.现在本地新建一个目录setup,将zookeeper压缩包复制进去. ALT+P打开一个标签,操作如下put命令. ...
- 如何在TypeScript中使用第三方JavaScript框架
一.安装typings 使用npm全局安装typings :npm install -g typings 安装成功. 二,搜索资源,支持模糊搜索:typings search base64 三.安装t ...
- linux之硬盘管理fdisk
1.首先我们用虚拟机模拟服务器加入一块新的硬盘,硬盘容量入下图5GB硬盘. 2.首先我们要对它进行分区,我们从上面知道需要分区格式化的是第二块硬盘. 3.输入n回车是新建分区,p是主分区(只能建立4个 ...
- uname -r查询版本不是安装的版本的问题
uname -r 查出来的版本与/lib/modules下面的内核版本不匹配.啥原因? 第一步,先strace uname -r看看这个uname -r到底从哪里获取的版本. strace没有看出来 ...
- Yii2的save()方法容易出错的地方
如果save()返回true, 但是数据没有保存成功,则应该是开启了事务且已经回滚 如果save()返回false, 则使用$model->errors查看错误原因 可以设置$model的场景, ...
- vs code安装
vs code是一款文本编辑器,开源,是前端界的vs,而Dreamweaver适合入门. user版本的一些系统分区文件夹无法创建,可能存在语言显示问题.一般用户建议使用system版. 下载链接:h ...
- PDO访问Mysql数据库
$dsn = 'mysql:host=127.0.0.1;dbname=myblog'; $username = 'root'; $pwd = '; $pdo = new PDO($dsn,$user ...
- Express static 托管静态文件 理解
今天偶尔看了一下服务端渲染,遇到了express.static, 在以前学习webpack配置服务端渲染时,也使用express.static 中间件,两者配置不太一样,由于当时也没有认真学,所以 一 ...
- vuex2.0 基本使用(2) --- mutation 和 action
我们的项目非常简单,当点击+1按钮的时候,count 加1,点击-1按钮的时候,count 减1. 1, mutation The only way to actually change state ...
- 弹出层-layui
type 0(信息框,默认)1(页面层)2(iframe层)3(加载层)4(tips层) 弹出层 //winIndex存储弹出层的index,以便关闭弹出层时使用 function openWindo ...