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 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 104), 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
邻接表,每次记录与某个点有关的边的条数,然后标记这个点。最后判断是否是能有m条边就ok。
代码:
#include <bits/stdc++.h>
using namespace std;
int first[],nex[],u[],v[];
int n,m,k,nv,ve,visited[];
int main()
{
memset(first,-,sizeof(first));
cin>>n>>m;
for(int i = ;i < m;i ++)
{
cin>>u[i]>>v[i];
nex[i] = first[u[i]];
first[u[i]] = i;
u[i + m] = v[i];
v[i + m] = u[i];
nex[i + m] = first[u[i + m]];
first[u[i + m]] = i + m;
}
cin>>k;
while(k --)
{
int c = ;
cin>>nv;
for(int i = ;i < nv;i ++)
{
cin>>ve;
visited[ve] = k;
int ver = first[ve];
while(ver != -)
{
if(visited[v[ver]] != k)
{
c ++;
}
ver = nex[ver];
}
}
if(c == m)cout<<"Yes"<<endl;
else cout<<"No"<<endl;
}
}
1134. Vertex Cover (25)的更多相关文章
- 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 (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 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
题意:给出一个图和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 ...
- 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 ...
随机推荐
- Found duplicate classes/resources
很可能是多个三方依赖重复了,依赖个插件,这个插件能查找出依赖关系, duplicate-finder-maven-plugin 使用命令显示 mvn dependency:tree [INFO] \- ...
- 基于球分割的空间二叉树检索算法(sphere-kdtree)
sphere-kdtree算法思路说明 具体思路如下: 第一.球半径分割,即利用不同的球半径,将三维空间点(向量)分割成多块.所以首先要求确定的就是分割多少块,怎么设置半径最合理. 第二.三维空间点平 ...
- python调用c++类方法(2)
testpy.cpp: #include<iostream> #include<vector> struct point{ float pointx; float pointy ...
- Python深度学习读书笔记-4.神经网络入门
神经网络剖析 训练神经网络主要围绕以下四个方面: 层,多个层组合成网络(或模型) 输入数据和相应的目标 损失函数,即用于学习的反馈信号 优化器,决定学习过程如何进行 如图 3-1 所示:多个层 ...
- 506C Mr. Kitayuta vs. Bamboos
分析 代码 #include<bits/stdc++.h> using namespace std; #define int long long ],h[],now[],cnt[]; in ...
- Linux_Rsync远程同步备份服务器
目录 目录 Remote Sync 同步的类型 本地模式 远程模式 RSync列表模式 RSync 服务模式 Setup RSync service How to use the rsync comm ...
- Monkey测试:日志信息分析
在跑monkey时,我们需要将日志输出到文件,然后对日志信息进行分析. 一.输出日志到文件 在monkey命令后加>文件地址 如:adb shell monkey 1000>E:/text ...
- C 语言的运算符
算术运算 C 语言支持 + - * / % 五种运算,加减乘除取模. 所有 CPU 都内建加法器,可以完成加法操作.减法操作可以转为加法操作.大部分 CPU 都没有内置乘法器,此时编译器会把 * / ...
- MathType的配置问题;将word中的公式转换为mathtype格式失败,缺少OMML2MML.XSL
安装MathType后打开word报错 打开会出现以下问题: 首先,把startup添加到word的信任中心: 要确保路径被office信任.依次打开word->文件->选项->信任 ...
- python基础--函数1
# 一,为什么使用函数 # 1,可以使代码的组织结构清晰,可读性好 # 2,遇到重复的问题可以直接调用函数 # 3,功能扩展时,可直接修改,而无需每处都进行修改. # 二,函数为何物 # 函数对程序员 ...