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 10^4 ), 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:

N​v 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

#include<iostream> //水题
#include<vector>
using namespace std;
int main(){
int n, m;
cin>>n>>m;
vector<int> edge(m, 0);
for(int i=0; i<m; i++){
int s, e;
cin>>s>>e;
edge[i]=s*10000+e;
}
int k;
cin>>k;
for(int i=0; i<k; i++){
int nv, flag=0;
cin>>nv;
vector<int> visited(n+1, 0);
for(int j=0; j<nv; j++){
int t;
cin>>t;
visited[t]=1;
}
for(int j=0; j<m; j++){
int s=edge[j]/10000;
int e=edge[j]%10000;
if(visited[s]==0&&visited[e]==0)
flag=1;
}
flag==1?cout<<"No"<<endl:cout<<"Yes"<<endl;
}
return 0;
}

PAT 1134 Vertex Cover的更多相关文章

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

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

  2. PAT 甲级 1134 Vertex Cover

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

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

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

  5. 1134. 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 ...

  6. 1134 Vertex Cover

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

  7. PAT1134:Vertex Cover

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

  8. PAT_A1134#Vertex Cover

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

  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. GitLab: API is not accessibl

    git push -u origin masterGitLab: API is not accessiblefatal: Could not read from remote repository. ...

  2. js几种escape()解码与unescape()编码

    js几种escape()解码与unescape()编码 www.111cn.net 编辑:kepeer 来源:转载 一篇js几种escape()解码与unescape()编码函数,同时我们也和它和服务 ...

  3. 【转载】DNS原理及其解析过程

    1.在浏览器中输入www.qq.com域名,操作系统会先检查自己本地的hosts文件是否有这个网址映射关系,如果有,就先调用这个IP地址映射,完成域名解析. 2.如果hosts里没有这个域名的映射,则 ...

  4. MogileFS介绍

    MogileFS介绍 MogileFS 是一个开源的分布式文件存储系统,由LiveJournal旗下的Danga Interactive公司开发. Danga团队开发了包括 Memcached.Mog ...

  5. HTML 5语义元素

  6. 2019 第三届强网杯线上赛部分web复现

    0x00前言 周末打了强网杯,队伍只做得出来6道签到题,web有三道我仔细研究了但是没有最终做出来,赛后有在群里看到其他师傅提供了writeup和环境复现的docker环境,于是跟着学习一波并记录下来 ...

  7. 浅谈算法——splay

    BST(二叉查找树)是个有意思的东西,种类巨TM多,然后我们今天不讲其他的,我们今天就讲splay 首先,如果你不知道Splay是啥,你也得知道BST是啥 如上图就是一棵优美的BST,它对于每个点保证 ...

  8. 大数高精度加减乘除 51nod 1005 大数加法

    1005 大数加法 基准时间限制:1 秒 空间限制:131072 KB 分值: 0 难度:基础题  收藏  关注 给出2个大整数A,B,计算A+B的结果. Input 第1行:大数A 第2行:大数B ...

  9. Node“getTextContent() is undefined for the type Node”处理办法

    最近一个项目在MyEclipse导入后总是报getTextContent() is undefined for the type Node错误. 经过查找原来是因为Node类为JDK中自带的(org. ...

  10. 【转】数据倾斜是多么痛?spark作业/面试/调优必备秘籍

    原博文出自于: http://sanwen.net/a/gqkotbo.html 感谢! 来源:数盟 调优概述 有的时候,我们可能会遇到大数据计算中一个最棘手的问题——数据倾斜,此时Spark作业的性 ...