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. js中采用词法作用域

    所谓的 词法( 代码 )作用域, 就是代码在编写过程中体现出来的作用范围. 代码一旦写好, 不用执行, 作用范围就已经确定好了. 这个就是所谓词法作用域. 在 js 中词法作用域规则: 1.函数允许访 ...

  2. 基于php实现QQ授权登陆

    第一步: 首先登陆QQ互联首页https://connect.qq.com/进行个人/企业认证.大概审核时间在一周左右. 认证通过之后创建应用: 这里主要用到应用的APP ID 和 APP Key  ...

  3. 完美解决centos安装linux后不能上网的问题

    vi / etc /sysconfig/network-scripts/ifcfg-eth0 配置ip地址 DEVICE=eth0 HWADDR=00:0C:29:8C:F7:6F TYPE=Ethe ...

  4. 20145236《网络对抗》Exp 6 信息搜集与漏洞扫描

    20145236<网络对抗>Exp 6 信息搜集与漏洞扫描 一.基础问题回答 哪些组织负责DNS,IP的管理? 互联网名称与数字地址分配机构,简称ICANN机构,决定了域名和IP地址的分配 ...

  5. day10,11练习

    1.执行Python脚本两种方式? 略 2.简述位.字节关系? 8位一个字节 3.简述ASCII,Unicode,utf-8,gbk关系? ascii unicode utf8 4.请写出李杰分别用u ...

  6. vue之路由嵌套,子路由

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  7. android 模仿大众点评团购卷列表多余3条时折叠,点击时显示剩余全部的功能

    要实现这样一个效果:加载一组数据,当这组数据的条数超过2条时,则这显示两条,其余的隐藏,当点击“展开全部时”在显示余下的部分.效果如下图所示: 展开前的效果: 展开后的效果 : 实现思路:控制数据而不 ...

  8. LeetCode202:Happy Number 。C#版,在vs2010中通过,leetcode中Wrong Answer

    static List<int> nums = new List<int>(); public static bool IsHappy(int n) { int newint ...

  9. .NET的弹性及瞬间错误处理库Polly

    原文:.NET的弹性及瞬间错误处理库Polly 本文基本是官方说明的翻译和总结(https://github.com/App-vNext/Polly) 什么是Polly? Polly是一款基于.NET ...

  10. BZOJ 4804: 欧拉心算

    数论题不多BB,直接开始推导吧: \(\sum_{i=1}^n \sum_{j=1}^n \phi(gcd(i,j))\) \(=\sum_{i=1}^n \sum_{j=1}^n \sum_{d=1 ...