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. $Matrix-Tree$定理-理论

    $Matrix-Tree$ 矩阵的行列式 这个东西看了好久才明白 _ (:з」∠)_ 时间不够可以直接跳到第六段. 看到这种新定义,第一反应还是去翻百度百科: 但是这个讲解真的让人很迷惑...关键就是 ...

  2. 转://Oracle补丁及opatch工具介绍

    一. CPU(Critical Patch Update) 一个CPU内包含了对多个安全漏洞的修复,并且也包括相应必需的非安全漏洞的补丁.CPU是累积型的,只要安装最新发布的CPU即可,其中包括之前发 ...

  3. Git安装与配置——详细教程1

    1.下载Git客户端 想要安装Git首先要下载Git的安装包程序. Git安装包下载地址:https://git-scm.com/downloads/ 2.安装Git 双击安装程序进行安装: a. 欢 ...

  4. Qt 编程指南 4 按钮

    1按钮类的控件 逐个解释一下各个用途:(1)按压按钮 QPushButton最基本的按钮,点击该按钮通常是通知程序进行一个操作,比如弹个窗.下一步.保存.退出等等,这是经常用到的,操作系统里的对话框里 ...

  5. 20145236《网络对抗》Exp2 后门原理与实践

    20145236<网络对抗>Exp2 后门原理与实践 目录: 一.基础问题回答 二.常用后门工具实践 2.1 Windows获得Linux Shell 2.2 Linux获得Windows ...

  6. 马哥Python视频

    链接:https://pan.baidu.com/s/1KMXqdXlaIjZ3OaZ-PUwE9A 密码私聊我

  7. day14 Python集合的补充

    python_1 = ['charon','pluto','ran','charon'] linux_1 = ['ran','xuexue','ting'] p_s = set(python_1) l ...

  8. day06数据类型----元组、字典、集合

    一.元组(tuple):     python中将一些不能修改的值称为不可变的,而不可变的列表则被称之为元组. 注意元组一旦被定义则不可修改,因此一般我们不定义空元组. 元组是有序的,可存放多个数据| ...

  9. ASP 基础一 网站开发 初步认识

    一 .ASP 与 ASP.NET的区别 i.ASP是解释型的动态语言,asp文件包含了前端和动态语言VBScript,来实现对服务器的交互,运行在IIS.PWS等WEB服务器上 II.ASP.NET是 ...

  10. linxu自定义安装及网络配置

    1.VMware及Centos6下载 链接:https://pan.baidu.com/s/1XMgBXA13e2zovijhcyciIA   提取码:5sqg 2.安装VMware:略 3.安装虚拟 ...