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. JSP-Runoob:JSP 教程

    ylbtech-JSP-Runoob:JSP 教程 1.返回顶部 1. JSP 教程 JSP 与 PHP.ASP.ASP.NET 等语言类似,运行在服务端的语言. JSP(全称Java Server ...

  2. bzoj 1700: [Usaco2007 Jan]Problem Solving 解题【dp】

    很像贪心的dp啊 这个定金尾款的设定让我想起了lolita和jk制服的尾款地狱-- 设f[i][j]为从j到i的付定金的最早月份然后从f[k][j-1]转移来,两种转移f[i][j]=min(f[i] ...

  3. bzoj 1630: [Usaco2007 Demo]Ant Counting【dp】

    满脑子组合数学,根本没想到dp 设f[i][j]为前i只蚂蚁,选出j只的方案数,初始状态为f[0][0]=1 转移为 \[ f[i][j]=\sum_{k=0}^{a[i]}f[i-1][j-k] \ ...

  4. Springboot拦截器线上代码失效

    今天想测试下线上代码,能否正常的执行未登录的拦截.所以把拦截器的代码给开放出来,但是没想到线上代码addInerceptors(InterceptorRegistry registry) 这个方法一直 ...

  5. P2973 [USACO10HOL]赶小猪

    跟那个某省省选题(具体忘了)游走差不多... 把边搞到点上然后按套路Gauss即可 貌似有人说卡精度,$eps≤1e-13$,然而我$1e-12$也可以过... 代码: #include<cst ...

  6. Linux C编程 GCC的使用

    本篇文章面向一些会linux文件操作与vim基本命令,编程大佬请移步勿喷. gcc是默认安装的,但是其还缺少常用的头文件和库文件,所以还需要build-essential这个包,可以在联网状态下使用如 ...

  7. ViewPager(1)FragmentPagerAdapter

    FragmentPagerAdapter 适合只有少量的pager,所有pager同时全部存在,不会有被销毁的,page过多很容易内存溢出. 1,代码 1.1 ViewPagerMain.java i ...

  8. 国内使用pip / pip with GFW / pip 镜像

    sudo pip install -i https://pypi.doubanio.com/simple/ YOUR_PACKAGE_NAME --trusted-host pypi.doubanio ...

  9. Jquery 全选、反选问题的记录

    <div id="list"> <ul id="choseList" > <li><input type=" ...

  10. LN : Eden Bitset_3

    Appreciation to our TA, 王毅峰, who designed this task. 问题描述 Give you N numbers a[1]...a[n] and M numbe ...