题意:给出一个图和k个查询,每个查询给出Nv个结点,问与这些结点相关的边是否包含了整个图的所有边。

思路:首先,因为结点数较多,用邻接表存储图,并用unordered_map<int,unordered_map<int,bool>> mp;表示两个顶点的相邻关系。查询时,每读入一个结点,就删除与该结点相邻的所有邻边,若最后删除的边数恰等于图的总边数,输出Yes;否则输出No。ps.其实无需额外用vector<int> Adj[]存储图,因为unordered_map<int,unordered_map<int,bool>> mp就可以表示一个图了。

代码:

#include <cstdio>
#include <vector>
#include <unordered_map>
using namespace std;
;
vector<int> Adj[maxn];

int main()
{
    int n,m;
    scanf("%d%d",&n,&m);
    unordered_map<int,unordered_map<int,bool>> mp,tmpMp;
    int u,v;
    ;i<m;i++){
        scanf("%d%d",&u,&v);
        Adj[u].push_back(v);
        Adj[v].push_back(u);
        mp[u][v]=mp[v][u]=true;
    }
    int k,queryCnt;
    scanf("%d",&queryCnt);
    ;i<queryCnt;i++){
        scanf("%d",&k);
        tmpMp=mp;
        ;//表示被删掉的边数
        ;j<k;j++){
            scanf("%d",&v);
            ;i<Adj[v].size();i++){//删除结点v的邻边
                int u=Adj[v][i];
                if(tmpMp[v][u]==true){
                    cnt++;
                    tmpMp[v][u]=tmpMp[u][v]=false;
                }
            }
        }
        if(cnt==m) printf("Yes\n");
        else printf("No\n");
    }
    ;
}

1134 Vertex Cover的更多相关文章

  1. PAT甲级——1134 Vertex Cover (25 分)

    1134 Vertex Cover (考察散列查找,比较水~) 我先在CSDN上发布的该文章,排版稍好https://blog.csdn.net/weixin_44385565/article/det ...

  2. PAT 甲级 1134 Vertex Cover

    https://pintia.cn/problem-sets/994805342720868352/problems/994805346428633088 A vertex cover of a gr ...

  3. PAT 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 le ...

  4. 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 le ...

  5. PAT Advanced 1134 Vertex Cover (25) [hash散列]

    题目 A vertex cover of a graph is a set of vertices such that each edge of the graph is incident to at ...

  6. PAT1134:Vertex Cover

    1134. Vertex Cover (25) 时间限制 600 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue A vertex ...

  7. 集合覆盖 顶点覆盖: set cover和vertex cover

    这里将讲解一下npc问题中set cover和vertex cover分别是什么. set cover: 问题定义: 实例:现在有一个集合A,其中包含了m个元素(注意,集合是无序的,并且包含的元素也是 ...

  8. URAL 2038 Minimum Vertex Cover

    2038. Minimum Vertex Cover Time limit: 1.0 secondMemory limit: 64 MB A vertex cover of a graph is a ...

  9. A1134. Vertex Cover

    A vertex cover of a graph is a set of vertices such that each edge of the graph is incident to at le ...

随机推荐

  1. 指定library路径

    1.执行 ?.jar文件: 1.1.“java -jar ?.jar” 1.2.如果 ?.jar里面使用了JNI调用了 ?.dll/?.so 等文件,可能会报错 找不到相关的 库文件,如果这样的话,可 ...

  2. LeetCode第[55]题(Java):Jump Game

    题目:跳跳游戏 难度:Medium 题目内容: Given an array of non-negative integers, you are initially positioned at the ...

  3. Android调用系统相机拍照保存照片很小解决方案

    保存图片小的一般操作步骤: 1. 调用系统相机 Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); startActivityFo ...

  4. PL/SQL通过修改配置文件的方式实现数据库的连接

    http://jingyan.baidu.com/article/c74d600080632a0f6a595d80.html

  5. zzuli 2179 最短路

    2179: 紧急营救 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 89  Solved: 9 SubmitStatusWeb Board Descri ...

  6. HTML 中 id与name 区别

    一个name可以同时对应多个控件,比如checkbox和radio而id必须是全文档中唯一的 id的用途1) id是HTML元素的Identity,主要是在客户端脚本里用.2) label与form控 ...

  7. LeetCode OJ:Valid Anagram(有效字谜问题)

    Given two strings s and t, write a function to determine if t is an anagram of s. For example,s = &q ...

  8. 视图框架:Spring MVC 4.0(1)

    目录 一.表单标签库 1.1.简介 1.2.常用属性 1.3.form标签与input标签 1.4.checkbox标签 1.5.radiobutton标签 1.6.password标签 1.7.se ...

  9. Qt中QT_BEGIN_NAMESPACE和QT_END_NAMESPACE的作用

    在Qt中,我们经常会看到 QT_BEGIN_NAMESPACE class QAction; class QMenu; class QPlainTextEdit; QT_END_NAMESPACE 这 ...

  10. Kotlin 第二弹:Android 中 PDF 创建与渲染实践

    这是 Kotlin 练习的的第二篇.这一篇的由来是因为刚刚在 Android 开发者官网查看 API 的时候,偶然看到了角落里面的 pdf 相关. 我仔细看看了详细文档,发现这个还蛮有意思的,关键是编 ...