PAT_A1134#Vertex Cover
Source:
Description:
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 Mlines 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 ['s are the indices of the vertices.
Output Specification:
For each query, print in a line
Yesif the set is a vertex cover, orNoif 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
Keys:
Attention:
- vis[n]设为哨兵,少声明一个变量-,-
Code:
/*
Data: 2019-05-29 19:57:25
Problem: PAT_A1134#Vertex Cover
AC: 19:55 题目大意:
若集合中各顶点的边的集合 = 整个图的边集,称该顶点集为VC集;
判断所给顶点集合是否为VC集
输入:
第一行给出,顶点数N和边数M,均<=1e4
接下来M行,给出顶点对
接下来一行,给出测试数K<=100
接下来K行,首先给出顶点数N,接下来N个数表示N个顶点 基本思路:
遍历各条边,若存在一条边的两个顶点均不在集合中,则非VC集
*/ #include<cstdio>
#include<algorithm>
const int M=1e4+;
using namespace std;
struct node
{
int v1,v2;
}adj[M];
int vis[M]; int main()
{
#ifdef ONLINE_JUDGE
#else
freopen("Test.txt", "r", stdin);
#endif int n,m,k,v,v1,v2;
scanf("%d%d", &n,&m);
for(int i=; i<m; i++)
{
scanf("%d%d", &v1,&v2);
adj[i].v1=v1;
adj[i].v2=v2;
}
scanf("%d", &k);
while(k--)
{
scanf("%d", &v);
fill(vis,vis+M,);
for(int i=; i<v; i++){
scanf("%d", &v1);
vis[v1]=;
}
for(int i=; i<m; i++){
if(vis[adj[i].v1]== && vis[adj[i].v2]==){
vis[n]=;break;
}
}
if(vis[n]) printf("No\n");
else printf("Yes\n");
} return ;
}
PAT_A1134#Vertex Cover的更多相关文章
- 集合覆盖 顶点覆盖: 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 ...
- 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 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 甲级 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 ...
- 四川第七届 D Vertex Cover(二分图最小点覆盖,二分匹配模板)
Vertex Cover frog has a graph with nn vertices v(1),v(2),…,v(n)v(1),v(2),…,v(n) and mm edges (v(a1), ...
随机推荐
- post and get
POST和GET是Web编程中的两个术语,他们是通过URI访问resource的两种方式.简单的说, GET 是把要访问的资源嵌入在URI中. 假设你在一个页面 http://www.myphone. ...
- IBM CEO罗睿兰:科技公司屹立百年的3个秘诀
假设有不论什么科技公司能够完美阐释"转型"这个词的含义,那么这家公司非创立103年的IBM莫属. 如今,它的变化更胜以往. 在<財富>杂志周二于美国加利福尼亚州拉古纳尼 ...
- Eclipse集成Resinserver
因为Resin在Eclipse下的表现丝毫不亚于Tomcat,小编决定带领众小弟一起学习使用Resin.虽然小编身边也没有什么大牛在使用Resin,但看到Resin的广告已经吹到天边了.所以还 ...
- Bean Query 改动Bug的版本号(1.0.1)已公布
改动内容: 修复输入对象被排序的属性不存在或者为Null时出错的bug 在Maven项目中引用 <dependency> <groupId>cn.jimmyshi</gr ...
- SQL数据库问题 解释一下下面的代码 sql 存储过程学习
SQL数据库问题 解释一下下面的代码 2008-08-13 11:30wssqyl2000 | 分类:数据库DB | 浏览1154次 use mastergocreate proc killspid( ...
- bzoj 2005 & 洛谷 P1447 [ Noi 2010 ] 能量采集 —— 容斥 / 莫比乌斯反演
题目:bzoj 2005 https://www.lydsy.com/JudgeOnline/problem.php?id=2005 洛谷 P1447 https://www.luogu.org/ ...
- 什么是 less? 如何使用 less?
什么是 Less? Less 是一门 CSS 预处理语言,它扩充了 CSS 语言,增加了诸如变量.混合(mixin).嵌套.函数等功能,让 CSS 更易编写.维护等. 本质上,Less 包含一套自定义 ...
- Django day01 web应用程序 , http协议
一:web应用程序1.什么是web应用程序 是一种可以通过web访问的应用程序,最大的好处就是, 只要有浏览器,用户就能很容易访问到应用程序 2. web应用程序的优缺点 缺点: 应用程序强调了浏览器 ...
- Blender插件加载研究
目标 [x] 解析Blender插件代码加载原理, 为测试做准备 结论 采用方法3的方式, 可以在测试中保证重新加载子模块, 是想要的方式, 代码如下: _qk_locals = locals() d ...
- 基于artDialog的扩展
/* * * 引用此文件必须引用以下两个资源文件,并且还要引用jQuery * <link href="ui-dialog.css" rel="stylesheet ...