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
Yes
if the set is a vertex cover, orNo
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
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), ...
随机推荐
- [bzoj3192][JLOI2013]删除物品_树状数组_栈
删除物品 bzoj-3192 JLOI-2013 题目大意:给你n个物品,分成2堆.所有的物品有不同的优先级.我只可以将一堆中的堆顶移动到另一个堆的堆顶.而如果当前物品是全局所有物品中优先级最高的,我 ...
- C#实现所有经典排序算法汇总
C#实现所有经典排序算法1.选择排序 class SelectionSorter { private int min; public void Sort(int[] arr) { ; i < a ...
- mysql无密码重启
mysql无密码重启 /etc/init.d/mysql stopnohup /usr/bin/mysqld_safe --user=mysql --skip-grant-tables &
- Delphi 中控件路径加入不进去解决方法
使用notepa++打开project中的*.dproj文件,在里面找到相似例如以下的区域 <DCC_UnitSearchPath>T:\BusinessSkinForm1006Sourc ...
- iOS - 社会化分享-微信分享,朋友圈分享
我仅仅做了文字和图片分享功能 1. TARGETS - Info - URL Types identifier -> weixin URL Schemes -> 应用id 2.在AppD ...
- bzoj 1045 [HAOI2008] 糖果传递 —— 贪心
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1045 好像是贪心...但这是一个环... 看博客:http://hzwer.com/2656 ...
- 初识Java,Java语言概述
Java语言是SUN(斯坦福大学网络公司)公司1995年推出的一门高级编程语言,由此James Gosling被公认为Java语言之父.Java语言起初运用在小型的家用电子产品上,后来随着互联网的发展 ...
- Iframe 用法的详细讲解
1转自:https://blog.csdn.net/judyge/article/details/51786064 zIframe 用法的详细讲解 把iframe解释成“浏览器中的浏览器“很是恰当 & ...
- 阿里云centos系统上安装ftp
最近需要在一台阿里云的云服务器上搭建FTP服务器,在这篇博文中分享一下我们根据实际需求进行的一些配置. ftp软件用的是vsftpd. vsftpd是一款在Linux发行版中最受推崇的FTP服务器程序 ...
- 修改DIV滚动条样式
/*滚动条样式*/ div::-webkit-scrollbar { /*滚动条整体样式*/ width: 5px; /*高宽分别对应横竖滚动条的尺寸*/ height: 5px; } div::-w ...