UVA Graph Coloring
主题如以下:
| Graph Coloring |
You are to write a program that tries to find an optimal coloring for agiven graph. Colors are applied to the nodes of the graph and the only availablecolors are black and white. The coloring of the graph is called optimalif a maximum of nodes is black.
The coloring is restricted by the rule thatno two connected nodes may be black.

Figure: An optimal graph with three black nodes
Input and Output
The graph is given as a set of nodes denoted by numbers
,
,and a set of undirected edges denoted by pairs of node numbers
,
. The input file contains
mgraphs. The number m is given on the first line. The first line ofeach graph contains
n and k, the number of nodes and the numberof edges, respectively. The following
k lines contain the edges givenby a pair of node numbers, which are separated by a space.
The output should consists of 2m lines, two lines for each graphfound in the input file. The first line of should contain the maximum numberof nodes that can be colored black in the graph. The second line shouldcontain one possible optimal coloring.
It is given by the list of blacknodes, separated by a blank.
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
求图中黑色节点的最大个数,黑色节点不能相邻,看起来挺简单的(实际上也非常easy。
。
。),但自己NC,超时又WA了几次,没理解清晰DFS中的cur的含义,我原意cur是推断过的节点个数,但这样确定不了递归边界,假设边界是cur==n,那么每次递归都得推断n个点,非常浪费时间,有些点是明显不可能的。
后来改成cur是当前要推断的点的下标。思路清晰多了,但还存在一个问题:若当前节点不能染色,要不要递归下去?细致想想就会发现,肯定须要递归下去。不然达不到递归边界。但假设当前节点能够染色。是不是仅仅把当前节点染色,然后递归?这样能够过例子。但会WA,由于这样漏掉了非常多情况。这样就相当于从第一个点開始推断。然后第一个点肯定能被染色。然后再依次看其他点,总共就一种方案,但总共同拥有多种染色方案。所以说即使当前节点能够染色,也要递归不染该节点的情况。
AC的代码例如以下:
版权声明:本文博客原创文章,博客,未经同意,不得转载。
UVA Graph Coloring的更多相关文章
- POJ 1419 Graph Coloring(最大独立集/补图的最大团)
Graph Coloring Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 4893 Accepted: 2271 ...
- 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. ...
- Graph Coloring I(染色)
Graph Coloring I https://www.nowcoder.com/acm/contest/203/J 题目描述 修修在黑板上画了一些无向连通图,他发现他可以将这些图的结点用两种颜色染 ...
- poj 1419 Graph Coloring
http://poj.org/problem?id=1419 题意: 一张图黑白染色,相邻点不能都染黑色,最多能染几个黑色点 最大点独立集 但是图不能同构为二分图,不能用二分图匹配来做 那就爆搜吧 还 ...
- 【POJ】1419:Graph Coloring【普通图最大点独立集】【最大团】
Graph Coloring Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 5775 Accepted: 2678 ...
- 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.如果有合法方案, ...
- uva 193 Graph Coloring(图染色 dfs回溯)
Description You are to write a program that tries to find an optimal coloring for a given graph. Col ...
随机推荐
- 修改Hosts不生效的一个场景-web(转)
Update: 如果浏览器使用了代理工具,修改 Hosts 也不会生效.这里是因为,浏览器会优先考虑代理工具(如添加 pac 文件.SwitchySharp等)的代理,建议调试的时候先关闭这些代理. ...
- Qt on Android: Qt 5.3.0 公布,针对 Android 改进的说明
5月20日本,Qt 官方博客宣布 Qt 5.3.0 公布! 这个版本号聚焦在性能.稳定性和可用性的提升上,与 5.1 / 5.2 相比有非常大提升. 5.3.0 的主要变化: 稳定能.可用性大大提升 ...
- 【Espruino】NO.06 关键是你的仆人(继续)
http://blog.csdn.net/qwert1213131/article/details/27834551 本文属于个人理解,能力有限,纰漏在所难免.还望指正. [小鱼有点电] 这几天一直在 ...
- Bob大叔观OO原则
Bob大叔观OO原则 上篇总结了经典的23种 设计模式,详细的解读后期会陆续的详细揭开.使用设计模式的根本原因就是为了增强代码的复用性和可维护性.而面向对象是实现代码复用的有效途径,所以这里有必要了解 ...
- NSIS:实现程序窗口逐渐透明的渐入渐出效果
原文NSIS:实现程序窗口逐渐透明的渐入渐出效果 需要修改版的插件(支持timer功能): MUI:InstallOptions.dll MUI2:nsDialogs.dll 以及system插件,( ...
- github中origin和upstream的区别(转)
Fork,本身并不是git工具中的一个命令,也不是对git的扩展,它是在GitHub上的概念,是另一种clone方式——在服务器端的clone.而我们通常意义上的clone,是将远程repo 复制一份 ...
- 使用 Advanced Installer 打包 一键安装Web应用程序
原文:使用 Advanced Installer 打包 一键安装Web应用程序 安装预览: 资源下载: 示例安装包 操作流程: 1.新建Asp.net Application. 2.设置应用程序名称和 ...
- Linux系统下启动MySQL报错:Neither host 'localhost.localdomain' nor 'localhost' could be looked up with
Linux系统下启动MySQL报错:Neither host 'localhost.localdomain' nor 'localhost' could be looked up with 摘要 Li ...
- Https 客户端与服务器交互过程梳理(转)
本文试图以通俗易通的方式介绍Https的工作原理,不纠结具体的术语,不考证严格的流程.我相信弄懂了原理之后,到了具体操作和实现的时候,方向就不会错,然后条条大路通罗马.阅读文本需要提前大致了解对称加密 ...
- Asp.net .net(C#) 获取当前命名空间,类名,方法名的方法
public static string GetMethodInfo() { string str = ""; //取得当前方法命名空间 str += & ...