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 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:
Nv [ [
where Nv 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】的更多相关文章
- PAT甲级——1134 Vertex Cover (25 分)
1134 Vertex Cover (考察散列查找,比较水~) 我先在CSDN上发布的该文章,排版稍好https://blog.csdn.net/weixin_44385565/article/det ...
- PAT 甲级 1134 Vertex Cover
https://pintia.cn/problem-sets/994805342720868352/problems/994805346428633088 A vertex cover of a gr ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 【PAT甲级】1070 Mooncake (25 分)(贪心水中水)
题意: 输入两个正整数N和M(存疑M是否为整数,N<=1000,M<=500)表示月饼的种数和市场对于月饼的最大需求,接着输入N个正整数表示某种月饼的库存,再输入N个正数表示某种月饼库存全 ...
- pat甲级 1154 Vertex Coloring (25 分)
A proper vertex coloring is a labeling of the graph's vertices with colors such that no two vertices ...
- PAT甲级 1122. Hamiltonian Cycle (25)
1122. Hamiltonian Cycle (25) 时间限制 300 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue The ...
随机推荐
- wordpress Warning: Parameter 2 to qtranxf_postsFilter() expected to be a reference
wordpress qtranslate-x Warning: Parameter 2 to qtranxf_postsFilter() expected to be a reference Para ...
- Jenkins 搭建 .NET Core 持续集成环境
关于c#的.Net FrameWork 的集成环境以及MsBuild的配置可以看 jenkins搭建.NET FrameWork持续集成环境 这篇文章 关于.NET Core 这个项目 ...
- java两个栈实现一个队列&&两个队列实现一个栈
栈:先进后出 队列:先进先出 两个栈实现一个队列: 思路:先将数据存到第一个栈里,再将第一个栈里的元素全部出栈到第二个栈,第二个栈出栈,即可达到先进先出 源码: class Queue<E&g ...
- Web响应的提高
想象一下,如果用户在页面上触发一个点击事件,结果反应延迟比较明显,这将是一个令人沮丧的事情.而造成这个问题的原因就是响应延迟. 浏览器UI 线程 大家都知道浏览器的UI线程,大多数浏览器都是一个独立的 ...
- JavaWeb学习篇之----web应用的虚拟目录映射和主机搭建(Tomcat)
从今天开始来学习JavaWeb的相关知识,之前弄过一段时间JavaWeb的,就是在做毕业设计的时候搞过,但是那时候完全是为了任务去学习,所以效果不好,好多东西都没有深入的研究过,所以接下来的一段时间我 ...
- NX二次开发-UFUN新建工程图UF_DRAW_create_drawing
NX9+VS2012 #include <uf.h> #include <uf_draw.h> #include <uf_part.h> UF_initialize ...
- ecshop 学习笔记
ECSHOP各文件夹功能说明 1.根目录:前台程序文件2.admin:后台程序文件夹 --根目录:后台程序文件 *.php文件 --help\zh_cn:各功能的帮助文件 *.xml文件 ...
- Solrj API读取core 索引库数据
private static String zkHost = "ip:2181,ip:2181,ip:2181"; private static CloudSolrServer s ...
- Array类型中的检测数组,转换方法,栈方法,队列方法
我的新博客==> http://www.suanliutudousi.com/2017/08/24/array%E7%B1%BB%E5%9E%8B%E4%B8%AD%E7%9A%84%E6%A3 ...
- 注意:字符串substring方法在jkd6,7,8中的差异。
标题中的substring方法指的是字符串的substring(int beginIndex, int endIndex)方法,这个方法在jdk6,7是有差异的. substring有什么用? sub ...