1134 Vertex Cover
题意:给出一个图和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的更多相关文章
- PAT甲级——1134 Vertex Cover (25 分)
1134 Vertex Cover (考察散列查找,比较水~) 我先在CSDN上发布的该文章,排版稍好https://blog.csdn.net/weixin_44385565/article/det ...
- PAT 甲级 1134 Vertex Cover
https://pintia.cn/problem-sets/994805342720868352/problems/994805346428633088 A vertex cover of a gr ...
- 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 ...
- 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 ...
- 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 ...
- PAT1134:Vertex Cover
1134. Vertex Cover (25) 时间限制 600 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue A vertex ...
- 集合覆盖 顶点覆盖: set cover和vertex cover
这里将讲解一下npc问题中set cover和vertex cover分别是什么. set cover: 问题定义: 实例:现在有一个集合A,其中包含了m个元素(注意,集合是无序的,并且包含的元素也是 ...
- 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 ...
- 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 ...
随机推荐
- 报错HTTP Status 500 - Unable to instantiate Action
报错如下: HTTP Status 500 - Unable to instantiate Action, visitAction, defined for 'visit_toAddPage' in ...
- spring:设置映射访问路径 或 xml配置访问路径 (spring mvc form表单)
项目hello, 在src/main/java下面建一个目录: charpter2 一.xml配置访问路径 web.xml <web-app> <display-name>Ar ...
- 5.8 页面对象(Page Object)模式
页面对象(Page Object)模式是目前自动化测试领域普遍使用的设计模式之一,此模式可以大大提高测试代码的复用率,提高测试脚本的编写效率和维护效率,是中级自动化测试工程师的必备技能之一. 1.页面 ...
- 解决:夜神模拟器连不上adb的问题
一. adb devices发现不了设备 刚试了一下,在夜神模拟器开启的情况下,adb devices 死活找不到设备 adb kill-server和adb start-server也无济于事 二. ...
- Python之virtualenv沙盒环境
在开发Python应用程序的时候,系统安装的Python3只有一个版本:3.4.所有第三方的包都会被pip安装到Python3的site-packages目录下. 如果我们要同时开发多个应用程序,那这 ...
- New Concept English three (33)
31 45 We have all experienced days when everything goes wrong. A day may begin well enough, but sudd ...
- Redis 补充
Redis 补充 Redis 的主要用途 数据库 缓存和消息中间件 相当于一个字典 数据库切换 select 1 (默认36个数据库 默认在0) 1 基本数据类型 字符串 散列 hashes 列表 集 ...
- Visual Studio 2013中用VSIX创建项目模版
我会一步一步解释: 我的一个项目里有5个工程, 我想用其中的4个去创建一个新的工具模版,我还想把他们都放到一个文件夹下面当我用这个模版创建新的工程时.注意我的初始化项目,我想把他们转换成一个模版(我不 ...
- Skynet服务器框架(八) 任务和消息调度机制
引言: 在我看来,消息和任务调度应该是skynet的核心,整个skynet框架的核心其实就是一个消息管理系统.在skynet中可以把每个功能都当做一个服务,整个skynet工程在执行过程中会创建很多个 ...
- hihocoder-1483区间价值 (二分+尺取法)
题目链接: 区间价值 给定n个数A1...An,小Ho想了解AL..AR中有多少对元素值相同.小Ho把这个数目定义为区间[L,R]的价值,用v[L,R]表示. 例如1 1 1 2 2这五个数所组成的区 ...