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

mmp,看了半天都没有看懂题,英语弱到爆
百度后才知道,每条边至少有一个顶点存在set总,则该set是vertex cover

 #include <iostream>
#include <vector>
using namespace std;
int a, b, n, m, k,nv;
int main()
{
cin >> n >> m;
vector<pair<int, int>>graph(m);
for (int i = ; i < m; ++i)
cin >> graph[i].first >> graph[i].second;
cin >> k;
while (k--)
{
cin >> nv;
vector<bool>map(n, false);
while (nv--)
{
cin >> a;
map[a] = true;
}
bool flag = true;
for (int i = ; flag&&i < m; ++i)
if (map[graph[i].first] == false && map[graph[i].second] == false)//没有一个顶点存在map中
flag = false;
cout << (flag ? "Yes" : "No") << endl;
}
return ;
}

PAT甲级——A1134 Vertex Cover【25】的更多相关文章

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

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

  7. 【PAT甲级】1070 Mooncake (25 分)(贪心水中水)

    题意: 输入两个正整数N和M(存疑M是否为整数,N<=1000,M<=500)表示月饼的种数和市场对于月饼的最大需求,接着输入N个正整数表示某种月饼的库存,再输入N个正数表示某种月饼库存全 ...

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

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

  9. PAT甲级 1122. Hamiltonian Cycle (25)

    1122. Hamiltonian Cycle (25) 时间限制 300 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue The ...

随机推荐

  1. java-----Long转换为 int , string

    int: 1.调用intValue()方法 long ll = 300000; int ii= new Long(ll).intValue(); 2.先把long转换成字符串String,然后在转行成 ...

  2. bzoj1293题解

    [题意分析] 给你一条有n个点的数轴,每个点属于一个种类,总共有k个种类.求一段最短的线段,使对于每个种类,这段线段上有至少一个点属于它. [算法分析] 1.对于50%的数据,N≤10000 对于每一 ...

  3. iOS 多层级的immutable objects 转换成 mutable objects

    第一种方法是:将多层级的递归转换 方法: +(id) recursiveMutable:(id)object { if([object isKindOfClass:[NSDictionary clas ...

  4. 最常见VC++编译错误信息集合

    1.fatal error C1010: unexpected end of file while looking for precompiled header directive. 寻找预编译头文件 ...

  5. sqoop2安装总结

    sqoop2安装 1. 下载解压缩 此次安装版本为1.99.6 # Decompress Sqoop distribution tarball tar -xvf sqoop-<version&g ...

  6. [21]APUE:线程同步之记录锁(文件)

    [a] 概念 建议锁:在遵循相同记录锁规则的进程/线程间生效,通常用于保证某个程序自身多个进程/线程间的数据一致性 强制锁:意在保证所有进程间的数据一致性,但不一定有效:如不能应对先 unlink 后 ...

  7. Rabbit MQ 基础入门

    Rabbit MQ 学习(一)基础入门 简介 RabbitMQ 简介 为什么选择 RabbitMQ RabbitMQ 的模型架构是什么? AMQP 协议是什么? AMQP 常用命令 概念 生产者和消费 ...

  8. varnish(转http://www.ttlsa.com/nginx/varnish-4-configure-file/)

    2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 ...

  9. Poi设置列样式

    最近做的项目中用到Poi导出Excel文件做模板,其中有的列需要设置为文本格式,查资料发现都是给单元格设置样式,由于是模板单元格都没内容,所以不能通过设置单元格式样式的方式操作,网上有说法是不能设置列 ...

  10. 在线文库解决方案Jacob+SwfTools+FlexPaper

    课程作业,准备做一个类似于豆丁之类的在线文库,解决方案也就是将文档(doc ppt xls)等转换成pdf,然后转成swf展示在页面中,今天下午经过研究,参考其他人的博客,实现了这个主要功能,这里也做 ...