PAT 甲级 1134 Vertex Cover
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:
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
代码:
#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的更多相关文章
- PAT甲级——1134 Vertex Cover (25 分)
1134 Vertex Cover (考察散列查找,比较水~) 我先在CSDN上发布的该文章,排版稍好https://blog.csdn.net/weixin_44385565/article/det ...
- 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 ...
- 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 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 ...
- 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 甲级 1154 Vertex Coloring
https://pintia.cn/problem-sets/994805342720868352/problems/1071785301894295552 A proper vertex color ...
- pat甲级 1154 Vertex Coloring (25 分)
A proper vertex coloring is a labeling of the graph's vertices with colors such that no two vertices ...
- 1134 Vertex Cover
题意:给出一个图和k个查询,每个查询给出Nv个结点,问与这些结点相关的边是否包含了整个图的所有边. 思路:首先,因为结点数较多,用邻接表存储图,并用unordered_map<int,unord ...
- PAT甲级目录
树(23) 备注 1004 Counting Leaves 1020 Tree Traversals 1043 Is It a Binary Search Tree 判断BST,BST的性质 ...
随机推荐
- SSM后台管理系统(Spring SpringMVC Mybatis Mysql EasyUI)
非常简单的一个后台管理系统,功能不多,框架也不复杂, 源码下载(附数据库)-ssm后台管理系统框架(Spring mvc + mybatis + mysql + easyui ) 实例图片
- Thinkphp5.0整合个推例子
最近做一个后台发送消息推送到app(android和ios)的功能,该功能采用的是个推接口,基于php的,我用TP5来实现这个推送流程.先看官方demo吧.可以先参考官方给到的例子来看http://d ...
- leetcode 206. Reverse Linked List(剑指offer16)、
206. Reverse Linked List 之前在牛客上的写法: 错误代码: class Solution { public: ListNode* ReverseList(ListNode* p ...
- Java/JSP程序连接不上Mysql驱动问题解决方法
错误提示: java.lang.ClassNotFoundException: com.mysql.jdbc.Driverat java.net.URLClassLoader$1.run(URLCla ...
- <<linux device driver,third edition>> Chapter 4:Debugging Techniques
Debugging by Printing printk lets you classify messages accoring to their severity by associating di ...
- jmeter(二十)阶梯式加压测试
性能测试中,有时需要模拟一种实际生产中经常出现的情况,即:从某个值开始不断增加压力,直至达到某个值,然后持续运行一段时间. 在jmeter中,有这样一个插件,可以帮我们实现这个功能,这个插件就是:St ...
- 源码分享篇:使用Python进行QQ批量登录
直接上源码 1 #coding=utf-8 2 __author__ = 'Eagle' 3 import os 4 import time 5 import win32gui 6 import wi ...
- Luogu4099 HEOI2013 SAO 组合、树形DP
传送门 值得注意的是一般的DAG的拓扑序列数量是NP问题,所以不能直接入手 题目中给出的图可以看做是一个树形图,虽然方向比较迷.考虑使用树形图的性质 不妨任选一个点为根做树形DP,注意到数的位置与方案 ...
- React-简书视频学习总结
react的基础语法 redux这个数据层框架 react-redux如何方便我们在react中使用redux react-router 4.0 这样的非常实用的相关的第三方模块儿 immutable ...
- [Oracle]快速生成大量模拟数据的方法
快速生成大量模拟数据的方法: create table TEST(id integer, TEST_NUMBER NUMBER(18,6)); insert into TEST select i+j, ...