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.

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
#include <iostream>
#include <vector>
using namespace std;

int main(){
    int n, m, a, b;
    cin >> n >> m;
    vector<int> nv[n];
    
    for (int i = 0; i < m; i++) {
        cin >> a >> b;
        nv[a].push_back(i);
        nv[b].push_back(i);
    }
    
    int k, p, t;
    cin >> k;
    for (int i = 0; i < k; i++) {
        bool ans[m];
        fill(ans, ans+m, false);
        cin >> p;
        
        for (int j = 0; j < p; j++) {
            cin >> t;
            for (int k = 0; k < nv[t].size(); k++) {
                ans[nv[t][k]] = true;
            }
        }
        
        bool flag = true;
        for (int j = 0; j < m; j++) {
            if (!ans[j]) {
                flag = false;
                break;
            }
        }
        
        if (flag) {
            cout << "Yes\n";
        }else{
            cout << "No\n";
        }
    }
    
    return 0;
}
 
目录
相关文章
|
Python
wxPython StaticText控件背景色透明
wxPython StaticText控件背景色透明
234 0
|
传感器 数据采集 供应链
港口智能化,我们这样做!
港口智能化,我们这样做!
554 0
港口智能化,我们这样做!
|
敏捷开发 持续交付 开发工具
阿里云云效产品使用问题之如何把单独的库移到组里面
云效作为一款全面覆盖研发全生命周期管理的云端效能平台,致力于帮助企业实现高效协同、敏捷研发和持续交付。本合集收集整理了用户在使用云效过程中遇到的常见问题,问题涉及项目创建与管理、需求规划与迭代、代码托管与版本控制、自动化测试、持续集成与发布等方面。
|
C++
【洛谷 B2025】输出字符菱形 题解(raw string literal)
使用`*`构建一个斜置的、对角线长度为5的菱形。无输入要求。输出示例:`*`、`***`、`*****`、`***`、` *`。代码实现使用C++,直接打印预定义字符串完成。
233 0
|
Web App开发 缓存 网络协议
get和post的区别!
get和post的区别!
|
Dubbo Java 应用服务中间件
带你读《Apache Dubbo微服务开发从入门到精通》——三、 Annotation配置(下)
带你读《Apache Dubbo微服务开发从入门到精通》——三、 Annotation配置(下)
401 98
|
缓存 人工智能 算法
TCP的滑动窗口和拥塞控制
TCP的滑动窗口和拥塞控制
230 0
|
数据安全/隐私保护
spring-boot-starter-data-elasticsearch es带x-pack后台配置
spring-boot-starter-data-elasticsearch es带x-pack后台配置
186 0
|
存储 Java 关系型数据库
8 种 Java- 内存溢出之三 -Permgen space
8 种 Java- 内存溢出之三 -Permgen space