码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • 1134 Vertex Cover


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

    1. 10 11
    2. 8 7
    3. 6 8
    4. 4 5
    5. 8 4
    6. 8 1
    7. 1 2
    8. 1 4
    9. 9 8
    10. 9 1
    11. 1 0
    12. 2 4
    13. 5
    14. 4 0 3 8 4
    15. 6 6 1 7 5 4 9
    16. 3 1 8 4
    17. 2 2 8
    18. 7 9 8 7 6 5 4 2

    Sample Output:

    1. No
    2. Yes
    3. Yes
    4. No
    5. No
    1. #include
    2. #include
    3. #include
    4. using namespace std;
    5. struct edge {
    6. int u, v;
    7. } a[10010];
    8. int n, m, k, s, v[10010];
    9. bool vis[10010];
    10. int main() {
    11. cin >> n >> m;
    12. for (int i = 0; i < m; i++) {
    13. cin >> a[i].u >> a[i].v;
    14. }
    15. cin >> k;
    16. while (k--) {
    17. cin >> s;
    18. bool flag = 0;
    19. memset(vis, 0, sizeof(vis));
    20. for (int i = 0; i < s; i++) {
    21. cin >> v[i];
    22. vis[v[i]] = 1;
    23. }
    24. for (int i = 0; i < m; i++) {
    25. if (!vis[a[i].u] && !vis[a[i].v]) {
    26. flag = 1;
    27. break;
    28. }
    29. }
    30. if (!flag) {
    31. cout << "Yes" << endl;
    32. } else {
    33. cout << "No" << endl;
    34. }
    35. }
    36. return 0;
    37. }
  • 相关阅读:
    OpenCV之形态学操作
    Ubuntu安装深度学习环境相关(yolov8-python部署)
    Chrome 103支持使用本地字体,纯前端导出PDF优化
    GB28181学习(八)——历史视音频的回放
    家庭收支记账管理系统(Java+Web+MySQL)
    记录react native 环境配置 brew install watchman 警告问题
    触摸控件——键盘录入之ASCII录入
    图片怎么加水印?建议收藏这些方法
    【论文笔记】Encoding cloth manipulations using a graph of states and transitions
    数据结构_最短路径Floyd算法(C语言)
  • 原文地址:https://blog.csdn.net/weixin_53199925/article/details/127932418
  • 最新文章
  • 攻防演习之三天拿下官网站群
    数据安全治理学习——前期安全规划和安全管理体系建设
    企业安全 | 企业内一次钓鱼演练准备过程
    内网渗透测试 | Kerberos协议及其部分攻击手法
    0day的产生 | 不懂代码的"代码审计"
    安装scrcpy-client模块av模块异常,环境问题解决方案
    leetcode hot100【LeetCode 279. 完全平方数】java实现
    OpenWrt下安装Mosquitto
    AnatoMask论文汇总
    【AI日记】24.11.01 LangChain、openai api和github copilot
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1
正则表达式工具 cron表达式工具 密码生成工具

京公网安备 11010502049817号