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 ...
随机推荐
- Event Sourcing - ENode(一)
分布式系统 摩尔定律如果一直能实现,不管是涉及或者实现一个OLTP的系统,我们是不是都会轻松点,用硬件堆就可以了.但是现在硬件已经在求变了,那么我们也得求变,云的概念如此之火,本质就是设施虚拟化,也可 ...
- 2年SQL Server DBA调优方面总结
原文:2年SQL Server DBA调优方面总结 2年SQL Server DBA调优方面总结 当2年dba 我觉得,有些东西需要和大家分享探讨,先书单. 书单 1.<深入解析SQL Serv ...
- js 网上见到的动画函数 备份
<script> function startMove(obj,json,fn){ clearInterval(obj.timer); obj.timer = setInterval(fu ...
- (大数据工程师学习路径)第三步 Git Community Book----基本用法(下)
一.比较提交 - Git Diff 1.比较提交 - Git Diff 你可以用 git diff 来比较项目中任意两个版本的差异. $ git diff master..test 上面这条命令只显示 ...
- javaScript在私有的属性和方法
javaScript并没有什么特别的语法来代表私人.保.或公共的属性和方法,在这一点上与 java或其他语言是不同的.JavaScript大家是共同的所有对象: var myobj={ mypop:1 ...
- 开源 自由 java CMS - FreeCMS2.0 签字
项目地址:http://www.freeteam.cn/ 会员注冊 打开浏览器,输入http://localhost:8080/register.jsp. 输入注冊信息后点击"注冊" ...
- 一个数据表对象(NSManagedObject)加入排序
eg:数据库表对象 @interface Meditation : NSManagedObject @property (nonatomic, retain) NSString * order;//用 ...
- Nyoj 三国志(dijkstra+01背包)
描述 <三国志>是一款很经典的经营策略类游戏.我们的小白同学是这款游戏的忠实玩家.现在他把游戏简化一下,地图上只有他一方势力,现在他只有一个城池,而他周边有一些无人占的空城,但是这些空城中 ...
- OCP-1Z0-051-标题决心-文章5称号
5. Which SQL statements would display the value 1890.55 as $1,890.55? (Choose three .) A. SELECT TO_ ...
- Oracle内存管理(五)
[深度分析--eygle]学习笔记 1.4. 2其他内存组件 Large Pool-大池是SGA的一个可选组件,通经常使用于共享server模式(MTS). 并行计算或 RMAN的备份恢复等操作. J ...