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 ...
随机推荐
- Delphi操作ACCESS技巧集
1.DELPHI中操作access数据库(建立.mdb文件,压缩数据库)以下代码在WIN2K,D6,MDAC2.6下测试通过,编译好的程序在WIN98第二版无ACCESS环境下运行成功.//在之前us ...
- NX二次开发-UFUN打开工程图UF_DRAW_open_drawing
NX9+VS2012 #include <uf.h> #include <uf_draw.h> #include <uf_part.h> UF_initialize ...
- luoguP5162 WD与积木
我怎么这么zz啊.... 法一: 枚举最后一层的方案:没了... 法二: 生成函数:没了. k*F^k(x),就是错位相减. 法三: 我的辣鸡做法:生成函数 求方案数,用的等比数列求和....多项式快 ...
- ionic-CSS:ionic 按钮
ylbtech-ionic-CSS:ionic 按钮 1.返回顶部 1. onic 按钮 按钮是移动app不可或缺的一部分,不同风格的app,需要的不同按钮的样式. 默认情况下,按钮显示样式为:dis ...
- 7 Scatter-loading Features
7.1 About scatter-loading The scatter-loading mechanism enables you to specify the memory map of an ...
- Invalid Rom
问题描述 原因说明 这多半是因为单片机超频被锁,就是HSE_VALUE设置的与实际值不一致,容易造成这个问题. 解放方法 1. 先正确配置 HSE_VLAUE, 看HSE_VALUE 修改问题. 2. ...
- AtCoder ABC 128F Frog Jump
题目链接:https://atcoder.jp/contests/abc128/tasks/abc128_f 题目大意 给定长度为 N 的序列$s_0, s_1, \dots, s_{N-1}$,现在 ...
- day 91 Django学习之django自带的contentType表
Django学习之django自带的contentType表 通过django的contentType表来搞定一个表里面有多个外键的简单处理: 摘自:https://blog.csdn.net ...
- oracle 管理表空间
表空间:是oracle数据库中最大的逻辑存储结构,与操作系统中的数据文件相对应,用于存储数据库中用户创建的所有内容 表空间>数据文件 4.1创建一个永久性表空间myspace create ta ...
- The Preliminary Contest for ICPC Asia Xuzhou 2019 G. Colorful String 回文树
签到提: 题意:求出每一个回文串的贡献 (贡献的计算就是回文串不同字符的个数) 题解: 用回文树直接暴力即可 回文树开一个数组cost[ ][26] 和val[ ] 数组: val[i]表示回文树上节 ...