码迷,mamicode.com
首页 > 其他好文 > 详细

1134 Vertex Cover (25 分)

时间:2019-08-05 00:12:32      阅读:91      评论:0      收藏:0      [点我收藏+]

标签:eset   一个   UNC   using   put   否则   rom   lis   cto   

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 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 N1) 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:

N?v?? [

where N?v?? 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


给n个结点m条边,再给k个集合。对这k个集合逐个进行判断。每个集合S里面的数字都是结点编号,
求问整个图所有的m条边两端的结点,是否至少一个结点出自集合S中。如果是,输出Yes否则输出No

直接存是第几条边就行,然后用个set

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 int n,m,k,p;
 4 vector<int> v[10005];
 5 set<int> s;
 6 int main(){
 7     cin >> n >> m;
 8     int x,y;
 9     for(int i = 1; i <= m; i++){
10         cin >> x >> y;
11         v[x].push_back(i);
12         v[y].push_back(i);
13     }
14     cin >> k;
15     while(k--){
16         cin >> p;
17         set<int> st;
18         for(int i = 0; i < p; i++){
19             cin >> x;
20             for(int j = 0; j < v[x].size(); j++){
21                 st.insert(v[x][j]);
22             }
23         }
24         if(st.size() == m){
25             cout <<"Yes"<<endl;
26         }else{
27             cout <<"No"<<endl;
28         }
29     }
30     return 0;
31 }

 






1134 Vertex Cover (25 分)

标签:eset   一个   UNC   using   put   否则   rom   lis   cto   

原文地址:https://www.cnblogs.com/zllwxm123/p/11300520.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!