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 104), 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

邻接表,每次记录与某个点有关的边的条数,然后标记这个点。最后判断是否是能有m条边就ok。

代码:

#include <bits/stdc++.h>
using namespace std;
int first[],nex[],u[],v[];
int n,m,k,nv,ve,visited[];
int main()
{
memset(first,-,sizeof(first));
cin>>n>>m;
for(int i = ;i < m;i ++)
{
cin>>u[i]>>v[i];
nex[i] = first[u[i]];
first[u[i]] = i;
u[i + m] = v[i];
v[i + m] = u[i];
nex[i + m] = first[u[i + m]];
first[u[i + m]] = i + m;
}
cin>>k;
while(k --)
{
int c = ;
cin>>nv;
for(int i = ;i < nv;i ++)
{
cin>>ve;
visited[ve] = k;
int ver = first[ve];
while(ver != -)
{
if(visited[v[ver]] != k)
{
c ++;
}
ver = nex[ver];
}
}
if(c == m)cout<<"Yes"<<endl;
else cout<<"No"<<endl;
}
}

1134. Vertex Cover (25)的更多相关文章

  1. PAT Advanced 1134 Vertex Cover (25) [hash散列]

    题目 A vertex cover of a graph is a set of vertices such that each edge of the graph is incident to at ...

  2. PAT甲级——1134 Vertex Cover (25 分)

    1134 Vertex Cover (考察散列查找,比较水~) 我先在CSDN上发布的该文章,排版稍好https://blog.csdn.net/weixin_44385565/article/det ...

  3. PAT 甲级 1134 Vertex Cover

    https://pintia.cn/problem-sets/994805342720868352/problems/994805346428633088 A vertex cover of a gr ...

  4. PAT 1134 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 ...

  5. 1134 Vertex Cover

    题意:给出一个图和k个查询,每个查询给出Nv个结点,问与这些结点相关的边是否包含了整个图的所有边. 思路:首先,因为结点数较多,用邻接表存储图,并用unordered_map<int,unord ...

  6. PAT1134:Vertex Cover

    1134. Vertex Cover (25) 时间限制 600 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue A vertex ...

  7. PAT_A1134#Vertex Cover

    Source: PAT A1134 Vertex Cover (25 分) Description: A vertex cover of a graph is a set of vertices su ...

  8. 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 ...

  9. 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 ...

随机推荐

  1. maven使用常见问题

    1.我写的是src/main/java/config/mybatis-cofig.xml 但总是报错 Could not find resource src/main/java/config/myba ...

  2. 在HTML标签元素中,绑定JS函数

    <a onclick="ShowMsg(this)" id="myA" href="#">按钮</a> //JS方法 ...

  3. React Native商城项目实战02 - 主要框架部分(tabBar)

    1.安装插件,cd到项目根目录下执行: $ npm i react-native-tab-navigator --save 2.主框架文件Main.js /** * 主页面 */ import Rea ...

  4. 【原创实现】C 多线程入门Demo CAS Block 2种模式实现

    分Cas和Block模式实现了demo, 供入门学习使用,代码全部是远程实现. 直接上代码: /* ================================================== ...

  5. TP3.2写分页

    用TP3.2写分页 手册上说的好难懂,我自己去网上找资料 ,现在整理一下,以后可能会用: 在Think下面有Page.class.php类: 我在这个下面放了一个function.php的(算是类吧又 ...

  6. robot framework断言

    一.基础 RobotFramework带有丰富的系统关键,使用时无需导入,直接使用,为写自动化用例带来了极大的方便:不能停留在知道或者是会得程度,只有熟练使用各关键字,才能提升自动化用例的写作效率.下 ...

  7. Delphi DbgridEh实现鼠标拖动选中列,并使复选框选中

    1.先设置表格列的属性 procedure TForm_TaskToDW.InitGrid;var  MyCol: TColumnEh;begin  with DBGridEh_Task do  be ...

  8. MySQL学习-入门语句以及增删查改

    1. SQL入门语句 SQL,指结构化查询语言,全称是 Structured Query Language,是一种 ANSI(American National Standards Institute ...

  9. kafka使用问题解决

    java.lang.UnsupportedClassVersionError:org/apach/kafka/comon/utils/Utils:Unsupport major.minor versi ...

  10. Paper Reading_Distributed System

    最近(以及预感接下来的一年)会读很多很多的paper......不如开个帖子记录一下读paper心得 Mark一个上海交通大学东岳网络工作室的paper notebook Mark一个大神的笔记 Ed ...