博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
1134. Vertex Cover (25)
阅读量:7251 次
发布时间:2019-06-29

本文共 1928 字,大约阅读时间需要 6 分钟。

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 118 76 84 58 48 11 21 49 89 11 02 454 0 3 8 46 6 1 7 5 4 93 1 8 42 2 87 9 8 7 6 5 4 2
Sample Output:
NoYesYesNoNo
#include 
#include
using namespace std;int main(){ int n, m, a, b; cin >> n >> m; vector
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;}
 

转载地址:http://zwebm.baihongyu.com/

你可能感兴趣的文章
利用ICG3000构建L2tp ×××
查看>>
dns记录
查看>>
我的友情链接
查看>>
paramiko在windows上的安装和使用
查看>>
xshll登录脚本
查看>>
让“云”无处不在-Citrix Xenserver之一 环境搭建
查看>>
IT 工具软件集合
查看>>
KVM虚拟化原理与实践
查看>>
WSFC 来宾群集架构
查看>>
快速寻找某IP地址所在的网络交换机端口 - Netdisco
查看>>
51CTO广东线下聚会-技术达人之夜总结篇
查看>>
Git 之——常用命令集合
查看>>
DNS服务器bind的架设笔记
查看>>
CentOS启动提示unexpected inconsistency;RUN fsck MANUALLY解决方法
查看>>
一个问题看系统数据库设计
查看>>
镜像仓库Harbor私服高可用策略分析及部署
查看>>
重写cnodejs学习整理
查看>>
从浏览器渲染的角度谈谈html标签的语义化
查看>>
文件权限及特殊权限管理SUID、SGID和Sticky
查看>>
iis 7 asp.net ajax post 请求字节过大报错问题解决办法
查看>>