题意:给出一个图和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. JT809 加密解密算法

    平台对接标准上说“在数据包发送之前,二进制数据包与伪随机序列按字节进行异或运算.加密算法如下:用N模伪随机序列发生器产生伪随机字节序列.将待传输的数据与伪随机码按字节进行异或运算”下面代码是C语言的代 ...

  2. 【OpenGL ES】关于VBO(Vertex Buffer Object)的一些坑——解析一些关于glBuffer的函数

    最近在写毕设的时候用到OpenGL ES中的VBO,由于对一些接口用到的变量不了解被坑得很惨,在此记录一下防止以后再被坑. 本文为大便一箩筐的原创内容,转载请注明出处,谢谢:http://www.cn ...

  3. angular js jquery中post请求的一点小区别

    这也是最近遇到的坑,还是之前那个项目,现在要实现登录功能. 背景:注册功能之前已经跑通了.前端用的是jquery后台是springMVC.鉴于注册和登录有些接口功能是类似的(比如注册确保邮箱是没有注册 ...

  4. js、jq、ajax之间的关系

    一句话:js是一种客户端脚本语言,jq是在js基础上封装起来的一个开发工具,ajax是基于js的一种技术(异步刷新). javascript是一种在客户端执行的脚本语言,用来给网页添加动态功能,使网页 ...

  5. USB转串口WIN8驱动安装

    http://jingyan.baidu.com/article/11c17a2c0bb606f446e39da0.html  //查看百度经验 http://jingyan.baidu.com/ar ...

  6. Qt中切换窗口功能的实现

    两条语句就能够实现了: this->newNC.setWindowFlags(Qt::WindowStaysOnTopHint); this->newNC.show(); mark一下,防 ...

  7. 如何切换到自定义的Activity

    一. 新建一个空的工程,并添加一个按钮 二.新建一个布局文件,命名为my_aty, 并添加一个文本 三.新建一个类,命名为MyAty,并重写onCreate函数 public void onCreat ...

  8. UI-定时器与动画使用总结

    #pragma mark - 定时器   ******************************************************************************* ...

  9. 自己如何获取ADO连接字符串

    自己如何获取ADO连接字符串 摘自:http://blog.csdn.net/zyq5945/article/details/5586423 有时候我们参考网上的ADO连接字符串写未必就能连接上数据库 ...

  10. oracle重建undo表空间

    create undo tablespace UNDOTBS2 datafile 'D:\oracle\product\10.2.0\oradata\ttonline\UNDOTBS02.DBF' s ...