zoukankan      html  css  js  c++  java
  • 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 }





  • 相关阅读:
    delegate
    URL、Session、Cookies、Server.Transfer、Application和跨页面传送,利弊比较
    C#中页面之间传值传参的六种方法
    Java学习之路:2、Mysql 链接与查询
    Java学习之路:1、HelloWorld
    Memcache 分布式解决方案 之 : 普通 Hash 分布
    每日一记:搭建Memcached + php 缓存系统
    四、记一次失败的 CAS 搭建 之 结果总是那么伤(客户端)
    三、记一次失败的 CAS 搭建 之 服务端配置
    二、记一次失败的 CAS 搭建 之 证书配置
  • 原文地址:https://www.cnblogs.com/zllwxm123/p/11300520.html
Copyright © 2011-2022 走看看