题意:

给出一个\(n\)个点\(m\)条边的无向图,现在要给若干个点染色,使得每条边都至少邻接一个被染色的顶点.问至少要给多少各点染色才能满足条件.

分析:

注意到题目中有一个很特殊的条件:

对于图中任意一条边\(u,v\),有\(min \{ u,v \} \leq 30\)

所以最坏的情况下,最多染30个点就可以满足条件.

所以用bitset维护一下当前被染色的点的情况即可.

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <bitset>
using namespace std; const int maxn = 30; bitset<500> g[maxn];
int n, m, tot, ans; void dfs(int d, bitset<500> t) {
int cnt = t.count();
if(cnt >= ans) return ;
if(d == tot) {
ans = min(ans, cnt);
return ;
} if(t[d]) dfs(d + 1, t);
else {
t[d] = 1;
dfs(d + 1, t);
t[d] = 0;
dfs(d + 1, t | g[d]);
}
} int main()
{
while(scanf("%d%d", &n, &m) == 2) {
tot = min(30, n);
for(int i = 0; i < tot; i++) g[i].reset(); while(m--) {
int x, y; scanf("%d%d", &x, &y);
x--; y--;
if(x > y) swap(x, y);
g[x][y] = 1;
if(y < tot) g[y][x] = 1;
} bitset<500> t;
t.reset();
ans = tot;
dfs(0, t);
printf("%d\n", ans);
} return 0;
}

2015四川省赛 D Vertex Cover 搜索的更多相关文章

  1. 2015 四川省赛 C Censor(哈希 | KMP)

    模式串为子串 KMP /* @author : victor */ #include <bits/stdc++.h> using namespace std; typedef long l ...

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

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

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

  4. PAT1134:Vertex Cover

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

  5. 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 ...

  6. PAT A1134 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 ...

  7. PAT 甲级 1134 Vertex Cover

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

  8. 二分图匹配 + 最小点覆盖 - Vertex Cover

    Vertex Cover Problem's Link Mean: 给你一个无向图,让你给图中的结点染色,使得:每条边的两个顶点至少有一个顶点被染色.求最少的染色顶点数. analyse: 裸的最小点 ...

  9. SCU - 4439 Vertex Cover (图的最小点覆盖集)

    Vertex Cover frog has a graph with \(n\) vertices \(v(1), v(2), \dots, v(n)\) and \(m\) edges \((v(a ...

随机推荐

  1. Typora--Draw Diagrams With Markdown

    Typora Typora supports some Markdown extension for diagrams, you could enable this feature from pref ...

  2. 洛谷 P1969 积木大赛

    题目描述 春春幼儿园举办了一年一度的“积木大赛”.今年比赛的内容是搭建一座宽度为n的大厦,大厦可以看成由n块宽度为1的积木组成,第i块积木的最终高度需要是hi. 在搭建开始之前,没有任何积木(可以看成 ...

  3. plsql过期注册

    Product Code:4t46t6vydkvsxekkvf3fjnpzy5wbuhphqzserial Number:601769password:xs374ca 打开plsql工具 点击注册即可

  4. nodejs 实践:express 最佳实践(八) egg.js 框架的优缺点

    nodejs 实践:express 最佳实践(八) egg.js 框架的优缺点 优点 所有的 web开发的点都考虑到了 agent 很有特色 文件夹规划到位 扩展能力优秀 缺点 最大的问题在于: 使用 ...

  5. 宿主机Windows访问虚拟机Linux文件(二)

    上一篇文章中详细讲述FTP服务(基于文件传输协议的服务),本文则介绍另一种能够实现此功能Telnet(Telecommunications network 远程登陆)服务.本文介绍的telnet我常用 ...

  6. Docker搭建

    环境基于CentOS64位,内核最好3.10. 1.下载安装 docker      dockersudo yum install docker-io (假如内核版本太低的话,会在下载安装Docker ...

  7. SQLServer 2012 Always on配置全过程

    AlwaysOn取数据库镜像和故障转移集群之长.AlwaysOn不再像故障转移集群那样需要共享磁盘,从而主副本和辅助副本可以更容易的部署到不同的地理位置:AlwaysOn还打破了镜像只能1对1的限制, ...

  8. Mysql的介绍和安装注意

    1.Mysql所属公司:Oracle 2.数据库类型:关系型数据库 3.开发语言:C++ 4.版本:企业收费版和社区免费版 5.搭建Mysql环境 点击下一步直到遇到选择数据库编码的时候选择utf-8 ...

  9. 机器学习&深度学习资料分享

    感谢:https://github.com/ty4z2008/Qix/blob/master/dl.md <Brief History of Machine Learning> 介绍:这是 ...

  10. python基础教程总结15——5 虚拟茶话会

    聊天服务器: 服务器能接受来自不同用户的多个连接: 允许用户同时(并行)操作: 能解释命令,例如,say或者logout: 容易拓展 套接字和端口: 套接字是一种使用标准UNIX文件描述符(file ...