• 1134 Vertex Cover (25 分)


    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:

    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


    给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 }





  • 相关阅读:
    一些比较水的题目
    oracle not in,not exists,minus 数据量大的时候的性能问题
    简单的oracle分页语句
    oracle 查询结果集运算
    Spring注解详解
    HTTP报头Accept 和 Content-Type的区别
    vue 实现分转元的 过滤器
    oracle or语句的坑
    CSS样式 让你的输入的小写自动变成大写。
    js 十分精确身份证验证
  • 原文地址:https://www.cnblogs.com/zllwxm123/p/11300520.html
Copyright © 2020-2023  润新知