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 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 10^4 ), 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 v[1] v[2]⋯v[Nv ]
where Nv is the number of vertices in the set, and v[i]'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<iostream> //水题
#include<vector>
using namespace std;
int main(){
int n, m;
cin>>n>>m;
vector<int> edge(m, 0);
for(int i=0; i<m; i++){
int s, e;
cin>>s>>e;
edge[i]=s*10000+e;
}
int k;
cin>>k;
for(int i=0; i<k; i++){
int nv, flag=0;
cin>>nv;
vector<int> visited(n+1, 0);
for(int j=0; j<nv; j++){
int t;
cin>>t;
visited[t]=1;
}
for(int j=0; j<m; j++){
int s=edge[j]/10000;
int e=edge[j]%10000;
if(visited[s]==0&&visited[e]==0)
flag=1;
}
flag==1?cout<<"No"<<endl:cout<<"Yes"<<endl;
}
return 0;
}
PAT 1134 Vertex Cover的更多相关文章
- 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 ...
- 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 ...
- 1134 Vertex Cover
题意:给出一个图和k个查询,每个查询给出Nv个结点,问与这些结点相关的边是否包含了整个图的所有边. 思路:首先,因为结点数较多,用邻接表存储图,并用unordered_map<int,unord ...
- PAT1134:Vertex Cover
1134. Vertex Cover (25) 时间限制 600 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue A vertex ...
- PAT_A1134#Vertex Cover
Source: PAT A1134 Vertex Cover (25 分) Description: A vertex cover of a graph is a set of vertices su ...
- 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 ...
随机推荐
- gitlab https
https://gitlab.com/gitlab-org/gitlab-ce/blob/master/doc/install/installation.md#using-https https:// ...
- 词典(二) 哈希表(Hash table)
散列表(hashtable)是一种高效的词典结构,可以在期望的常数时间内实现对词典的所有接口的操作.散列完全摒弃了关键码有序的条件,所以可以突破CBA式算法的复杂度界限. 散列表 逻辑上,有一系列可以 ...
- JVM系列-类加载机制
简介 在java中,类的声明周期总共分为以下几种: 加载(Loading),验证(Verification),准备(Preparation),解析(Analysis), 初始化(Initializat ...
- 台哥原创:java 连连看源码
2010年,迷上了玩连连看 随手就做了这个,正好手头有这些图片素材 游戏启动时,界面先铺上了一层透明幕布,然后这些兵器图片交替从上到下,从左到右出现.. 鼠标停在兵器格子上时,所在格子会有红色 ...
- js 事件循环机制 EventLoop
js 的非阻塞I/O 就是由事件循环机制实现的 众所周知 js是单线程的 也就是上一个任务完成后才能开始新的任务 那js碰到ajxa和定时器.promise这些异步任务怎么办那?这时候就出现了事件 ...
- 为什么前后端分离不利于seo
搜索引擎的基础爬虫的原理就是抓取你的url,然后获取你的html源代码并解析. 而你的页面通常用了vue等js的数据绑定机制来展示页面数据,爬虫获取到的html是你的模型页面而不是最终数据的渲染页面, ...
- Linux文件详解
一.Linux文件类型分:普通文件.目录文件.链接文件.设备文件.管道文件. 1.普通文件:由ls -al显示属性时,第一个属性为 [-],例如 [-rwxrwxrwx].包括: 纯文本文件(ASCI ...
- 9i 和 11 g 区别
9i 和 11 g 区别 9i 不支持 2/4/8G,只支持 2000/4000/8000 M的
- ActiveMQ命令行工具
命令行工具 命令行工具 n activemq——运行activemq代理 n activemq-admin——管理代理的实例 在5.0之前activemq-admin被分成多个脚本,例如 ...
- jQuery学习笔记(4)-设置元素的属性和样式
一.前言 本篇主要讲解如何使用jQuery获取和操作元素的属性和css样式 二."DOM属性"与元素属性 1.运行一下代码 <img src="/images/lo ...