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. Cocos2D的平台检查宏

    为了避免在非iOS平台包含UIKit.h文件,需要在Prefix.pch文件中添加一个条件判断: #if __CC_PLATFORM_IOS #import <UIKit/UIKit.h> ...

  2. Android下NDK开发环境搭建

    Android下NDK开发环境搭建 1.     AndroidNDK安装与配置 1.1  NDK简介 Android NDK是一套允许开发人员使用本地代码(如C/C++)进行Android APP部 ...

  3. 生产者消费者的java实现

    先看最简单的,也就是缓冲区的容量为1 缓冲区容量为1 import java.util.List; public class ProducerAndConsumer2 { static class A ...

  4. Struts2技术内幕 读书笔记二 web开发的基本模式

    最佳实践 在讨论基本模式之前,我们先说说一个词:最佳实践 任何程序的编写都得遵循一个特定的规范.这种规范有约定俗称的例如:包名全小写,类名每个单词第一个字母大写等等等等;另外还有一些需要我们严格遵守的 ...

  5. Visual studio2010和Modelsim配置SystemC开发(转)

    本文转自一博文. 一.编译System库 1. 下载SystemC library source code, 到http://www.systemc.org注册会员账号后,即可下载SystemC li ...

  6. 字符编辑技术C语言实现

    #include<string.h> #include<ctype.h> #include<stdio.h> /*插入函数 ccode待插入的字符 anystrin ...

  7. js定义数组的方法

    1.定义时赋值 var mycars=new Array("a","b","c") 2.new一个数组对象 var mycars=new A ...

  8. Word Break(动态规划)

    Given a string s and a dictionary of words dict, determine if s can be segmented into a space-separa ...

  9. SQL解决时间段重复合并问题

    合并时间段: 将连续或者重叠的时间段合并. create table timesheets ( task_id char(10) not null primary key, startdate dat ...

  10. centos6-7克隆主机网卡无法启动问题

    1,centos6和redhat6左右的版本  第一,先找到网卡的mac地址,将其配置在配置文件中,重新启动网卡. 故障产生的原因: 由于克隆虚拟机,vmware只是修改了虚拟机的名字等信息,并没有修 ...