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. 五大主流数字币钱包:imToken数字货币钱包,Bitcoin core钱包,BTS网页版钱包,AToken轻钱包,Blockchain

    AToken数字货币钱包 超容易上手支持五大主流币种   互联网 | 编辑: 王静涛 2017-12-28 09:58:33转载     国家监管部门已叫停数字货币交易,包括火币网.比特币中国.OKC ...

  2. KVM 常用命令

    显示虚拟机 virsh list --all 停止虚拟机 virsh destroy <name> 启动虚拟机 virsh start <name> 删除虚拟机 virsh u ...

  3. 一、Python环境的搭建

    1.python官方下载地址:https://www.python.org/:python现在有两个版本:python2.7.x和python3.x 2.安装:一路下一步,默认安装 3.配置环境变量: ...

  4. 4、Shiro之IniRealm以及用户登录认证,角色认证,权限认证

    1.我们在项目test文件夹下面新建resourse文件夹并将她设置为资源文件夹: 2.在resourse文件夹下面新建user.ini文件 user.ini文件里面声明一个用户: 先写一个用户标签[ ...

  5. springboot日期格式转换

    post: @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") GET: @Dat ...

  6. http-server 建立 HTTPS 服务

    1. 创建证书 进入要建立 HTTPS 服务的目录 openssl genrsa -out key.pem 1024 openssl req -new -key key.pem -out csr.pe ...

  7. Stream的并行计算

    一.Stream并行计算体验,利用多核加快计算速度 stream的并发,多个cpu执行同一个任务,提高效率: 需求:从1+...+10000000,看下各种计算方法的运行时间是多少 代码例子如下: p ...

  8. 阶段3 1.Mybatis_06.使用Mybatis完成DAO层的开发_8 properties标签的使用及细节

    properties 可以把数据库链接的配置放在上面的properties里面 #{占位符}的形式去引用上面的.下面的内容就是引用上面的内容的定义. 运行查询的方法测试一下 这样改造可以成功的运行程序 ...

  9. 自定义标记mark

    前言 pytest可以支持自定义标记,自定义标记可以把一个web项目划分多个模块,然后指定模块名称执行.app自动化的时候,如果想android和ios公用一套代码时,也可以使用标记功能,标明哪些是i ...

  10. Selenium学习之==>常见面试题

    转自:http://www.imdsx.cn/ 一.selenium中如何判断元素是否存在? expected_conditions模块提供了多种校验方式,我常用的一种是presence_of_ele ...