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. eclipse连接Mysql和测试

    一.前期准备: 1.eclipse 2.Mysql workbench 3.jdbc 下载地址:https://www.mysql.com/products/connector/ 点击JDBC Dri ...

  2. php7.2 下安装yaf扩展

    wget http://pecl.php.net/get/yaf-3.0.7.tgz  解压并进入目录: 1 tar -zxvf yaf-3.0.7* && cd yaf-3.0.7  ...

  3. jmeter常用性能监听器分析

    jmeter中提供了很多性能数据的监听器,我们通过监听器可以来分析性能瓶颈 本文以500线程的阶梯加压测试结果来描述图表. 常用监听器 1:Transactions per Second 监听动态TP ...

  4. 【BASIS系列】SAP Basis系统管理中重置用户缓冲哪些需要注意

    公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[BASIS系列]SAP Basis系统管理中重 ...

  5. Unix时间戳和Java 的 System.currentTimeMillis()的区别

  6. 极*Java速成教程 - (8)

    Java高级特性 注解 注解可以在代码之外添加更多的信息,更加完整地描述程序,帮助编译器进行工作,或者实现某些特定的Java代码之外的功能. 注解可以简化某些重复的流程,自动化那些过程. 注解的使用 ...

  7. Larkin’s NOI

    Larkin’s NOI Problem Description Larkin has been to Yantai to take part in NOI 2010!众所周知(do you know ...

  8. [BZOJ 3456]城市规划(cdq分治+FFT)

    [BZOJ 3456]城市规划(cdq分治+FFT) 题面 求有标号n个点无向连通图数目. 分析 设\(f(i)\)表示\(i\)个点组成的无向连通图数量,\(g(i)\)表示\(i\)个点的图的数量 ...

  9. Scrapy 教程(十)-管道与数据库

    Scrapy 框架将爬取的数据通过管道进行处理,即 pipelines.py 文件. 管道处理流程 一.定义 item item 表示的是数据结构,定义了数据包括哪些字段 class TianqiIt ...

  10. RouteReuseStrategy angular路由复用策略详解,深度刨析路由复用策略

    关于前端路由复用策略网上的文章很多,大多是讲如何实现tab标签切换历史数据,至于如何复用的原理讲的都比较朦胧,代码样例也很难适用各种各样的路由配置,比如懒加载模式下多级嵌套路由出口网上的大部分代码都会 ...