poj 1419 Graph Coloring
http://poj.org/problem?id=1419
题意:
一张图黑白染色,相邻点不能都染黑色,最多能染几个黑色点
最大点独立集
但是图不能同构为二分图,不能用二分图匹配来做
那就爆搜吧
还可以转化为补图的最大团问题
#include<cstdio>
#include<cstring>
#include<iostream> using namespace std; bool map[][];
int color[],res[]; int n,ans,cnt; void read(int &x)
{
x=; char c=getchar();
while(!isdigit(c)) c=getchar();
while(isdigit(c)) { x=x*+c-''; c=getchar(); }
} bool can(int s)
{
for(int i=;i<=n;++i)
{
if(map[s][i] && color[i]==) return false;
}
return true;
} void dfs(int p)
{
if(p>n)
{
ans=cnt;
int k=;
for(int i=;i<=n;++i)
{
if(color[i]==) res[++k]=i;
}
return;
}
if(cnt+n-p+<=ans) return;
if(can(p))
{
cnt++;
color[p]=;
dfs(p+);
cnt--;
}
color[p]=;
dfs(p+);
} int main()
{
int T;
read(T);
int m,x,y;
while(T--)
{
read(n); read(m);
memset(map,false,sizeof(map));
memset(color,,sizeof(color));
while(m--)
{
read(x); read(y);
map[x][y]=map[y][x]=true;
}
ans=cnt=;
dfs();
cout<<ans<<'\n';
for(int i=;i<ans;++i) cout<<res[i]<<' ';
cout<<res[ans]<<'\n';
}
}
| Time Limit: 1000MS | Memory Limit: 10000K | |||
| Total Submissions: 5384 | Accepted: 2515 | Special Judge | ||
Description
Figure 1: An optimal graph with three black nodes
Input
Output
Sample Input
1
6 8
1 2
1 3
2 4
2 5
3 4
3 6
4 6
5 6
Sample Output
3
1 4 5
poj 1419 Graph Coloring的更多相关文章
- POJ 1419 Graph Coloring(最大独立集/补图的最大团)
Graph Coloring Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 4893 Accepted: 2271 ...
- 【POJ】1419:Graph Coloring【普通图最大点独立集】【最大团】
Graph Coloring Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 5775 Accepted: 2678 ...
- POJ1419 Graph Coloring(最大独立集)(最大团)
Graph Coloring Time Limit: 1000MS Memor ...
- uva193 - Graph Coloring
Graph Coloring You are to write a program that tries to find an optimal coloring for a given graph. ...
- UVA Graph Coloring
主题如以下: Graph Coloring You are to write a program that tries to find an optimal coloring for agiven ...
- Graph Coloring I(染色)
Graph Coloring I https://www.nowcoder.com/acm/contest/203/J 题目描述 修修在黑板上画了一些无向连通图,他发现他可以将这些图的结点用两种颜色染 ...
- GPS-Graph Processing System Graph Coloring算法分析 (三)
HamaWhite 原创,转载请注明出处!欢迎大家增加Giraph 技术交流群: 228591158 Graph coloring is the problem of assignin ...
- CF-1354 E. Graph Coloring(二分图,背包,背包方案输出)
E. Graph Coloring 链接 n个点m条边的无向图,不保证联通,给每个点标号1,2,3.1号点个数n1,2号点个数n2,3号点个数n3.且每条边的两点,标号之差绝对值为1.如果有合法方案, ...
- 【poj1419】 Graph Coloring
http://poj.org/problem?id=1419 (题目链接) 题意 求一般图最大独立集. Solution 最大独立集=补图的最大团. 代码 // poj1419 #include< ...
随机推荐
- mybatis 原理
什么是Mybatis MyBatis 本是apache的一个开源项目iBatis, 2010年这个项目由apache software foundation 迁移到了google code,并且改名为 ...
- ASP.NET MVC 4.0 参考源码索引
http://www.projky.com/asp.netmvc/4.0/Microsoft/AspNet/Mvc/Facebook/FacebookAppSettingKeys.cs.htmlhtt ...
- IIS8.5 的环境下添加配置WCF服务!!!!!
添加步骤: 1.打开iis8.5,先部署wcf服务. 2.首先添加MIME类型 扩展名:“.svc” MIME类型:“application/octet-stream” 3.添加 处理程序映射 请求路 ...
- JabRef学习笔记(一)
JabRef简介 JabRef is an open source bibliography reference manager. The native file format used by Jab ...
- 第七周PSP&进度条
团队项目PSP 一.表格: C类型 C内容 S开始时间 E结束时间 I时间间隔 T净时间(mins) 预计花费时间(mins) 讨论 讨论beta阶段任务 10:00 12:30 28 270 ...
- linux下 XGCOM串口助手的安装
源码下载:http://code.google.com/p/xgcom/ 也可以自己搜索下载 首先先安装依赖库,直接运行命令 #sudo apt-get install libglib2.0- ...
- SpringBoot(六)_AOP统一处理请求
什么是AOP AOP 是一种编程范式,与编程语言无关: 将通用逻辑从业务逻辑中分离出来(假如你的业务是一条线,我们不在业务线上写一行代码就能完成附加任务!我们会把代码写在其他的地方): 具体实现 (1 ...
- 深入理解JAVA虚拟机阅读笔记3——垃圾回收器
一.垃圾收集器总览 新生代:Serial. ParNew. Parallel Scavenge 老年代:CMS.Serial Old. Parallel Old 最新的:G1 并行和并发的区别: 并行 ...
- ansible部署(pip安装)
centos7 pip安装 ansible 首先ansible基于python2.X 环境 默认centos都已经安装好了python2环境 安装可选性 ansible可以通过源码,yum,pip等方 ...
- Rabbit and Grass HDU - 1849 (Bash+Nim)
就是Bash 和 Nim 博弈的结合 可以直接 res ^= (Li + 1) % Mi 也可以 sg打个表 我打了个表 #include <iostream> #include &l ...