UVA 193 Graph Coloring 图染色 DFS 数据】的更多相关文章

题意:图上的点染色,给出的边的两个点不能都染成黑色,问最多可以染多少黑色. 很水的一题,用dfs回溯即可.先判断和当前点相连的点是否染成黑色,看这一点是否能染黑色,能染色就分染成黑色和白色两种情况递归,如果不能就单递归白色. 代码: #include <cstdio> #include <cstring> const int maxn = 110; int cas, v, e, M; bool g[maxn][maxn]; int color[maxn], rec[maxn]; v…
Description You are to write a program that tries to find an optimal coloring for a given graph. Colors are applied to the nodes of the graph and the only available colors are black and white. The coloring of the graph is called optimal if a maximum…
Graph Coloring I https://www.nowcoder.com/acm/contest/203/J 题目描述 修修在黑板上画了一些无向连通图,他发现他可以将这些图的结点用两种颜色染色,满足相邻点不同色. 澜澜不服气,在黑板上画了一个三个点的完全图.修修跟澜澜说,这个图我能找到一个简单奇环. 澜澜又在黑板上画了一个n个点m条边的无向连通图.很可惜这不是一道数数题,修修做不出来了. 澜澜非常得意,作为一位毒瘤出题人,有了好题当然要跟大家分享,于是他把这道题出给你做了. 输入描述:…
题目链接 题目描述 修修在黑板上画了一些无向连通图,他发现他可以将这些图的结点用两种颜色染色,满足相邻点不同色. 澜澜不服气,在黑板上画了一个三个点的完全图.修修跟澜澜说,这个图我能找到一个简单奇环. 澜澜又在黑板上画了一个n个点m条边的无向连通图.很可惜这不是一道数数题,修修做不出来了. 澜澜非常得意,作为一位毒瘤出题人,有了好题当然要跟大家分享,于是他把这道题出给你做了. 输入描述: 第一行两个整数n,m (1≤ n,m≤ 3*105),接下来m行每行两个整数ai,bi表示一条边 (1≤ a…
题意: 一个无向图的每条边为红色或蓝色,有这样一种操作:每次选一个点,使与其相邻的所有边的颜色翻转. 求解是否可以经过一系列操作使所有的边颜色相同,并输出最少操作次数和相应的点. 分析: 每个点要么选要么不选,也就是对某个点最多进行一次这样的操作. 可以先假设把所有的边变为红色,然后逐个连通分量处理. 对每个连通分量的第一个点,继续枚举是选还是不选. 再根据边的当前颜色和目标颜色,确定相邻顶点选还是不选,相当于二分图染色的过程. 比较两种方案选的点的个数的多少,把较优的保存下来. 然后以把所有的…
题目 \(dfs+\)证明. 对于题目描述,可以发现\(K\)其实就是大于等于原图中最大度数的最小奇数,因为如果原图度数最大为奇数,则最多颜色肯定为K,而如果原图最大度数为偶数,则\(K\)又是奇数,则最多颜色也肯定小于等于\(K\). 然后可以\(dfs\)染色,染色有两种方法,一种是枚举颜色,然后判断可行性并考虑回溯.这种搜索复杂度很大. 而另一种方法就是直接贪心搜索,使每个当前搜到的点取除去与它相连的颜色的最小值,然后并不需要判断可行性,因为每次都是将当前颜色尽可能的不相同. #defin…
主题如以下: 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…
Graph Coloring Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 5775   Accepted: 2678   Special Judge Description You are to write a program that tries to find an optimal coloring for a given graph. Colors are applied to the nodes of the…
http://poj.org/problem?id=1419 题意: 一张图黑白染色,相邻点不能都染黑色,最多能染几个黑色点 最大点独立集 但是图不能同构为二分图,不能用二分图匹配来做 那就爆搜吧 还可以转化为补图的最大团问题 #include<cstdio> #include<cstring> #include<iostream> using namespace std; ][]; ],res[]; int n,ans,cnt; void read(int &…
Map Coloring Time limit: 1.0 secondMemory limit: 64 MB We consider a geographical map with N countries numbered from 1 to N (0 < N < 99). For every country we know the numbers of other countries which are connected with its border. From every countr…