1134. Vertex Cover (25)

时间限制
600 ms
内存限制
65536 kB
代码长度限制
16000 B
判题程序
Standard
作者
CHEN, Yue

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

思路

判断一个集合的点是否覆盖了所有的边。

1.用vector保存所有的边(包含起止点)

2.将需要查询的点插入set容器中。

3.对于每一条边,检查它的起止点是否有至少一个点在集合中。如果有Yes,如果没有No。

代码

#include<iostream>
#include<vector>
#include<set>
using namespace std; class edge
{
public:
int a;
int b;
}; int main()
{
int N,M;
while(cin >> N >> M)
{
vector<edge> edges(M);
for(int i = 0; i < M; i++)
{
cin >> edges[i].a >>edges[i].b;
}
int K;
cin >> K;
for(int i = 0; i < K; i++)
{
int Nv;
cin >> Nv;
set<int> nodes;
for(int j = 0; j < Nv; j++)
{
int node;
cin >> node;
nodes.insert(node);
}
bool isCovered = true;
for(int v = 0; v < M; v++)
{
if(nodes.find(edges[v].a) == nodes.end() && nodes.find(edges[v].b) == nodes.end())
{
isCovered = false;
break;
}
}
if(isCovered)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
}
}

  

PAT1134:Vertex Cover的更多相关文章

  1. PAT-1134 Vertex Cover (图的建立 + set容器)

    A vertex cover of a graph is a set of vertices such that each edge of the graph is incident to at le ...

  2. 集合覆盖 顶点覆盖: set cover和vertex cover

    这里将讲解一下npc问题中set cover和vertex cover分别是什么. set cover: 问题定义: 实例:现在有一个集合A,其中包含了m个元素(注意,集合是无序的,并且包含的元素也是 ...

  3. URAL 2038 Minimum Vertex Cover

    2038. Minimum Vertex Cover Time limit: 1.0 secondMemory limit: 64 MB A vertex cover of a graph is a ...

  4. 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 ...

  5. 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 ...

  6. PAT 甲级 1134 Vertex Cover

    https://pintia.cn/problem-sets/994805342720868352/problems/994805346428633088 A vertex cover of a gr ...

  7. 二分图匹配 + 最小点覆盖 - Vertex Cover

    Vertex Cover Problem's Link Mean: 给你一个无向图,让你给图中的结点染色,使得:每条边的两个顶点至少有一个顶点被染色.求最少的染色顶点数. analyse: 裸的最小点 ...

  8. SCU - 4439 Vertex Cover (图的最小点覆盖集)

    Vertex Cover frog has a graph with \(n\) vertices \(v(1), v(2), \dots, v(n)\) and \(m\) edges \((v(a ...

  9. 四川第七届 D Vertex Cover(二分图最小点覆盖,二分匹配模板)

    Vertex Cover frog has a graph with nn vertices v(1),v(2),…,v(n)v(1),v(2),…,v(n) and mm edges (v(a1), ...

随机推荐

  1. 【一天一道LeetCode】#38. Count and Say

    一天一道LeetCode系列 (一)题目 The count-and-say sequence is the sequence of integers beginning as follows: 1, ...

  2. C语言设计模式-封装-继承-多态

    快过年了,手头的工作慢慢也就少了,所以,研究技术的时间就多了很多时间,前些天在CSDN一博客看到有大牛在讨论C的设计模式,正好看到了,我也有兴趣转发,修改,研究一下. 记得读大学的时候,老师就告诉我们 ...

  3. linux下显示不规则图片窗口

    测试环境是ubuntu15.04,使用的图形库是gtk+. 图片格式采用的是X11的xpm格式,首先从网上找一个背景透明的png图片,然后用图形转换工具(比如gimp)转换为xpm格式. 程序代码如下 ...

  4. 基于MT6752/32平台 Android L版本驱动移植步骤

    基于MT6752/32平台 Android L版本驱动移植步骤 根据MK官网所述,在Android L 版本上Turnkey ABS 架构将会phase out,而Mediatek Turnkey架构 ...

  5. LeetCode(61)-Valid Palindrome

    题目: Given a string, determine if it is a palindrome, considering only alphanumeric characters and ig ...

  6. 杭电ACM 1000题

    import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner cin=n ...

  7. 如何用Dreamweaver编辑rails的html.erb文件

    默认情况下用dw是以普通的text文件打开html.erb文件,这多少让人有点不爽.其实dw打开erb文件也是相当的容易,下面就简单说下在mac os X下如何让dw支持erb文件: 首先找到dw的用 ...

  8. 《转》优化UITableViewCell高度计算的那些事

    我是前言 这篇文章是我和我们团队最近对 UITableViewCell 利用 AutoLayout 自动高度计算和 UITableView 滑动优化的一个总结.我们也在维护一个开源的扩展,UITabl ...

  9. java keytool

    1.tomcat 配置Https,server.xml <Connector protocol="org.apache.coyote.http11.Http11Protocol&quo ...

  10. java——封装和关键字

    封装:将类的属性和方法的实现细节隐藏起来的过程 封装的好处:1重用性(代码)2,利于分工3,隐藏细节 访问关键字:public private 默认访问修饰符,protected static关键字 ...