https://pintia.cn/problem-sets/994805342720868352/problems/994805346428633088

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 1), 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​​ [ [

where N​v​​ is the number of vertices in the set, and ['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 <bits/stdc++.h>
using namespace std; const int maxn = 1e5 + 10; int N, M, T, K;
int x, vis[maxn]; vector<int> v[maxn];
bool flag = false;
int step = 0; int main() {
scanf("%d%d", &N, &M);
for(int i = 0; i < M; i ++) {
int st, en;
scanf("%d%d", &st, &en); v[st].push_back(i);
v[en].push_back(i);
}
scanf("%d", &T);
while(T --) {
step = 0;
memset(vis, 0, sizeof(vis));
scanf("%d", &K);
for(int i = 0; i < K; i ++){
scanf("%d", &x); for(int j = 0; j < v[x].size(); j ++) {
if(vis[v[x][j]] == 0) {
vis[v[x][j]] = 1;
step ++;
}
} } if(step == M) printf("Yes\n");
else printf("No\n");
}
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甲级——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 ...

  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 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 (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. PAT 甲级 1154 Vertex Coloring

    https://pintia.cn/problem-sets/994805342720868352/problems/1071785301894295552 A proper vertex color ...

  7. pat甲级 1154 Vertex Coloring (25 分)

    A proper vertex coloring is a labeling of the graph's vertices with colors such that no two vertices ...

  8. 1134 Vertex Cover

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

  9. PAT甲级目录

    树(23) 备注 1004 Counting Leaves   1020 Tree Traversals   1043 Is It a Binary Search Tree 判断BST,BST的性质 ...

随机推荐

  1. VCS双机+oracle 11gR2+ASM主机名修改

    ----------------------------------------------------------------------------VCS修改主机名---------------- ...

  2. Oracle数据文件改名

    1. open状态改名   SYS@userdata>select tablespace_name,file#,file_name,v.status,v.enabled from dba_dat ...

  3. ASP.NET Log4net 记录日志

    1.安装方式一(官网下载) 2.安装方式二(NuGet安装log4net) 3.使用步骤 4.自定义属性:UserIP UserName ActionsClick Message 概述:Log4net ...

  4. 3.4《想成为黑客,不知道这些命令行可不行》(Learn Enough Command Line to Be Dangerous)——grepping(检索目标行命令)

    grep是检查文件内容最强大的工具之一,这也许不能代表什么,但这不是重点.的确,grep常用作动词,比如'你完全应该检索(grep)那个文件'. grep最常用于在文件中搜索子字符串.例如,我们在第三 ...

  5. 在angularjs实现一个时钟

    想在网页上,显示当前系统时钟. <body ng-app="App2" ng-controller="Ctrl2"> <div ng-bind ...

  6. 两个非常好的bootstrap模板,外送大话设计模式!

    两个非常好的bootstrap模板,外送大话设计模式! 下载地址:http://download.csdn.net/download/wolongbb/10198756

  7. MonkeyRunner 模块

    用python编写脚本   1.导入模块: MonkeyRunner MonkeyDevice MonkeyImage ps:如果给导入模块起别名,就应该使用别名,而不能使用原名,否则会出现错误. f ...

  8. Nginx URL后面不加斜杠301重定向

    今天开发碰到一个问题,其实之前就有这个问题,但是一直都没去关注,今天测试碰到了就解决一下. 问题情况: 当我请求 http://admindev.jingruiauto.com/store/views ...

  9. vue + element 实现登录注册(自定义表单验证规则)

    注册页包含手机验证码登录和密码的二次验证. 效果如下: 实现代码: <template> <div> <div class="register-wrapper& ...

  10. 【JVM.3】虚拟机性能监控与故障处理工具

    一.概述 经过前面两章对于虚拟机内存分配与回收技术各方面的介绍,相信读者已经建立了一套比较完整的理论基础.理论总是作为指导实践的工具,能把这些执行应用到实际工作中才是我们的最终目的.接下来我们会从实践 ...