题意:

给出一个\(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;
}

最新文章

  1. Python正则式的基本用法
  2. fastx_toolkit软件使用说明
  3. MVC Create
  4. python Requests库在处理response时的一些陷阱
  5. ABAP程序中关于长文本的处理方法
  6. PowerShell读取Windows产品密钥
  7. Linux - 常用Shell快捷键
  8. 为什么Erlang比C慢那么多倍?
  9. Scrum会议1
  10. HDU 5285 wyh2000 and pupil
  11. Teamcity+SVN+VisualStudio在持续集成简明教程
  12. 互联网点对点通讯(P2P)
  13. 利用css3特性写出三角形(兼容IE浏览器)
  14. Docker 内核名字空间
  15. 翻译:replace into语句(已提交到MariaDB官方手册)
  16. Struts2 REST 插件 XStream 远程代码执行漏洞 S2-052 复现过程
  17. SkylineGlobe6.5遍历信息树节点方法
  18. P3301 [SDOI2013]方程
  19. V-rep学习笔记:Reflexxes Motion Library 2
  20. HTML|CSS之布局相关总结

热门文章

  1. SyntaxError: Use of const in strict mode.
  2. 有关在python中使用Redis(一)
  3. Java基础(Java概述、环境变量、注释、关键字、标识符、常量)
  4. 用配置文件方式启动mongodb集群
  5. Java TCP通信
  6. SAP ERP classification和C4C的同步
  7. UVA 1611 Crane 起重机 (子问题)
  8. coredata 删除与更新
  9. Bootstrap历练实例:嵌套的媒体对象
  10. Bootstrap历练实例:带徽章的列表组