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< ...
随机推荐
- python learning Network Programming.py
Socket # 用一个 Socke t表示"打开了一个网络连接" # 打开一个 Socket 需要知道目标计算机的IP地址和端口号,再指定协议类型即可. # TCP # 主动发起 ...
- 【CSAPP笔记】4. 汇编语言——基础知识
程序的机器级表示 计算机能读懂是机器代码(machine code)-- 用字节序列编码的低级操作 -- 也就是0和1.编译器基于编程语言的规则.目标机器的指令集和操作系统的规则,经过一系列阶段产生机 ...
- 6th Alpha阶段的postmortem报告
组名:好好学习(代组长发布) 会议重要内容记录: 1. 尝试在beta阶段实现的功能,与alpha阶段相比的优势 (1)更改软件现有的bug: 1)软件的账目只能输入,但是一旦发生失误却无法更改和 ...
- SQL语句查询一个数据库中的所有表
--读取库中的所有表名 select name from sysobjects where xtype='u' --读取指定表的所有列名 select name from syscolumns whe ...
- 用Html5与Asp.net MVC上传多个文件
html: <form action="/home/upload" method="post" enctype="multipart/form- ...
- [洛谷P4340][SHOI2016]随机序列
题目大意:有$n(n\leqslant10^5)$个数,每两个数之间可以加入$+-\times$三种符号,$q(q\leqslant10^5)$次询问,每次询问修改一个数后,所有表达式可能的值的和 题 ...
- BZOJ 3731: Gty的超级妹子树
3731: Gty的超级妹子树 Time Limit: 7 Sec Memory Limit: 32 MBSubmit: 346 Solved: 96[Submit][Status][Discus ...
- 【bzoj2034】 2009国家集训队—最大收益
http://www.lydsy.com/JudgeOnline/problem.php?id=2034 (题目链接) 题意 n个任务,每个任务只需要一个时刻就可以完成,完成后获得${W_i}$的收益 ...
- 面向对象高级编程(1)-使用__slots__
使用__slots__ 正常情况下,当我们定义了一个class,创建了一个class的实例后,我们可以给该实例绑定任何属性和方法,这就是动态语言的灵活性.先定义class: >>> ...
- Java EE之JSP
1.使用JSP的原因 编写Servlet代码的时候,向响应中输出HTML文档是非常不方便的. PrintWriter writer = response.getWriter(); writer.app ...