题意:给出一个图和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. java.util.logging.Logger_01

    1.参考网址 1.1.java.util.logging.Logger使用详解 http://lavasoft.blog.51cto.com/62575/184492 1.2.Java内置Logger ...

  2. CSS自定义字体(@font-face选择符)

    @font-face是CSS中的一个模块,他主要是把自己定义的Web字体嵌入到你的网页中,随着@font-face模块的出现,我们在Web的开发中使用字体不怕只能使用Web安全字体. 语法规则: @f ...

  3. Ajax基础(三)--eval的使用

    eval的使用: 1.定义和用法 计算某个字符串,并执行其中的js代码 eval(string) string必须,含有表达式或执行语句 string有返回值的话 2.实例 2.1 字符串上该用eva ...

  4. ZOJ 3203 Light Bulb(数学对勾函数)

    Light Bulb Time Limit: 1 Second      Memory Limit: 32768 KB Compared to wildleopard's wealthiness, h ...

  5. fastclick插件 导致 日期插件无法触发

    fastclick源文件中有这一行,加个if条件就可以了 当touchend的时候我们判断一下他的event.target到底是啥,如果是date我们就不玩了,不要你fastclick了,用原生的去触 ...

  6. react : code splitting

    1.webpack config output: { ... chunkFilename: 'js/[name].min.js' ... } optimization: { splitChunks: ...

  7. vue: data binding

    1.文本 第一种“Mustache” 语法(双大括号)写法第二种 用v-text的指今写法第三种和第四是对es6写法的拓展写法,称模板字符串 <template> <div> ...

  8. 读书笔记-Ribbon源码分析

    @LoadBalanced注解用来给RestTemplate做标记,以使用负载均衡的客户端来配置. 通过搜索LoadBalancerClient可以发现,LoadBalancerClient是Spri ...

  9. 学习window.open()及问题分析

    以前对window.open()理解的不透彻,最近因为产品需要,重新学习了一下,以下为一些收获和问题总结: 调用方式:window.open(url , winName , style); url:弹 ...

  10. 用 hash 找出指定一个数, 这个数是数组两个值的总和, 找出两个值的坐标

    var twoSum = function(nums, target) { var len = nums.length; var exist = {} //这里利用了hash来存放已知的 exist[ ...