题意:给出一个图和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. docker定义数据卷及数据卷的备份恢复

    前言:生产环境中使用docker时,往往需要对数据进行持久化(只有把容器导出为镜像,才能够保存写的数据,否则容器删除或者停止,所有数据都会没有),或者需要在多个容器之间进行数据共享,这必然涉及容器的数 ...

  2. STDIN_FILENO

    1.STDIN_FILENO的作用STDIN_FILENO属于系统API接口库,其声明为 int 型,是一个打开文件句柄,对应的函数主要包括 open/read/write/close 等系统级调用. ...

  3. No mojo definitions

    pom.xml <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</gro ...

  4. 将DLL注册到GAC

    使用方法如下: 方法1: (1).开始菜单->Microsoft Visual Studio 2010 ->Visual Studio Tools->Visual Studio Co ...

  5. 网络之Call Phone、Web、SMS、Email

    1. 准备工作:导入信息UI库 #import <MessageUI/MessageUI.h>2. Call Phone 方式一: 拼接字符串 注意开头是tel: 这种方式打电话回不到原来 ...

  6. UI-自定义TabBar

    MyCustomTabBar.h文件 #import <UIKit/UIKit.h> @interface MyCustomTabBar : UITabBarController @end ...

  7. Mark: admob for delphi xe4 integrated 80% -done!-95% to do more test

    Todo: admob 整合.  Integrated Admob with Delphi xe4.  2013-06-28 !done!  2013-07-01 Notice: You should ...

  8. 使用 minio 搭建私有对象存储云。aws-php-sdk 操作object

    How to use AWS SDK for PHP with Minio Server aws-sdk-php is the official AWS SDK for the PHP program ...

  9. JFinal自定义FreeMarker标签

    为什么采用freemarker? 1.模板技术,不依附于语言和框架,前端和后端解耦,便于分工协作,更好的协同. 2.页面相应速度快 3.前端非常的灵活,采用自定义标签可以在不更改后端的基础上很容易的构 ...

  10. BZOJ - 2957 (分块/线段树)

    题目链接 本质是维护斜率递增序列. 用分块的方法就是把序列分成sqrt(n)块,每个块分别用一个vector维护递增序列.查询的时候遍历所有的块,同时维护当前最大斜率,二分找到每个块中比当前最大斜率大 ...