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), ...
随机推荐
- linux环境下安装varnish
Varnish是一款高性能的开源HTTP加速器,挪威最大的在线报纸 Verdens Gang 使用3台Varnish代替了原来的12台Squid,性能比以前更好. sudo apt-get insta ...
- 2014腾讯实习生笔试题——define与typedef
2014腾讯实习生笔试(广州站)第26题填空题: #define MAX_NUM 1000+1 int Temp = Max_NUM*10; 则Temp的值为( ) 答案是:1010, 由于宏定义仅仅 ...
- 一条SQL语句求每月连续低温时间
近期为某个项目写存储过程做统计.其中有个是这样的: 求每个月至少连续3个小时低于某个温度值的时间(小时). 假设有个全年温度表: CREATE TABLE #t(m INT, h INT ,t DEC ...
- 自适应阈值分割—大津法(OTSU算法)C++实现
大津法是一种图像灰度自适应的阈值分割算法,是1979年由日本学者大津提出,并由他的名字命名的.大津法按照图像上灰度值的分布,将图像分成背景和前景两部分看待,前景就是我们要按照阈值分割出来的部分.背景和 ...
- [BZOJ 1735] Muddy Fields
[题目链接] https://www.lydsy.com/JudgeOnline/problem.php?id=1735 [算法] 二分图最小覆盖 [代码] #include<bits/stdc ...
- IJ:Idea 常用代码
ylbtech-IJ:Idea 常用代码 1.返回顶部 1. 1.JeePlus/代码生成器http://localhost:8081/a/login 2.manager/Java基础框架http:/ ...
- 3d数学 7 矩阵
7.1 矩阵-数学定义 在线性代数中, 矩阵就是以行和列形式组织的矩形数字块.矩阵是向量的数组. 7.1.1 矩阵的维度和记法 矩阵的维度被定义为它包含了多少行和多少列.一个\(r \times c\ ...
- 最近积累的JS 东西,分享一下
js 关闭页面 var browserName=navigator.appName; if (browserName=="Netscape") { window.open('',' ...
- nginx单机1w并发设置
关闭keep-live,提高链接回收 keeplive_timeout 0; events{ worker_connections 1024; } more /proc/sys/net/core/so ...
- Android java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader......couldn't find "libweibosdkcore.so
java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/ ...