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';
}
}
Graph Coloring
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 5384   Accepted: 2515   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 graph and the only available colors are black and white. The coloring of the graph is called optimal if a maximum of nodes is black. The coloring is restricted by the rule that no two connected nodes may be black.

 
Figure 1: An optimal graph with three black nodes 

Input

The graph is given as a set of nodes denoted by numbers 1...n, n <= 100, and a set of undirected edges denoted by pairs of node numbers (n1, n2), n1 != n2. The input file contains m graphs. The number m is given on the first line. The first line of each graph contains n and k, the number of nodes and the number of edges, respectively. The following k lines contain the edges given by a pair of node numbers, which are separated by a space.

Output

The output should consists of 2m lines, two lines for each graph found in the input file. The first line of should contain the maximum number of nodes that can be colored black in the graph. The second line should contain one possible optimal coloring. It is given by the list of black nodes, 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

poj 1419 Graph Coloring的更多相关文章

  1. POJ 1419 Graph Coloring(最大独立集/补图的最大团)

    Graph Coloring Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 4893   Accepted: 2271   ...

  2. 【POJ】1419:Graph Coloring【普通图最大点独立集】【最大团】

    Graph Coloring Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 5775   Accepted: 2678   ...

  3. POJ1419 Graph Coloring(最大独立集)(最大团)

                                                               Graph Coloring Time Limit: 1000MS   Memor ...

  4. uva193 - Graph Coloring

    Graph Coloring You are to write a program that tries to find an optimal coloring for a given graph. ...

  5. UVA Graph Coloring

    主题如以下: Graph Coloring  You are to write a program that tries to find an optimal coloring for agiven ...

  6. Graph Coloring I(染色)

    Graph Coloring I https://www.nowcoder.com/acm/contest/203/J 题目描述 修修在黑板上画了一些无向连通图,他发现他可以将这些图的结点用两种颜色染 ...

  7. GPS-Graph Processing System Graph Coloring算法分析 (三)

        HamaWhite 原创,转载请注明出处!欢迎大家增加Giraph 技术交流群: 228591158     Graph coloring is the problem of assignin ...

  8. CF-1354 E. Graph Coloring(二分图,背包,背包方案输出)

    E. Graph Coloring 链接 n个点m条边的无向图,不保证联通,给每个点标号1,2,3.1号点个数n1,2号点个数n2,3号点个数n3.且每条边的两点,标号之差绝对值为1.如果有合法方案, ...

  9. 【poj1419】 Graph Coloring

    http://poj.org/problem?id=1419 (题目链接) 题意 求一般图最大独立集. Solution 最大独立集=补图的最大团. 代码 // poj1419 #include< ...

随机推荐

  1. 20181126-java-面试知识-收集

    链接:最近面试java后端开发的感受:如果就以平时项目经验来面试,通过估计很难——再论面试前的准备 两本书的链接:Java Web轻量级开发面试教程和Java核心技术及面试指南.

  2. Alpha版本冲刺(九)

    目录 组员情况 组员1(组长):胡绪佩 组员2:胡青元 组员3:庄卉 组员4:家灿 组员5:凯琳 组员6:翟丹丹 组员7:何家伟 组员8:政演 组员9:黄鸿杰 组员10:刘一好 组员11:何宇恒 展示 ...

  3. modify headers插件的使用

    Modity headers是firefox浏览器的一个插件,作用是改变http请求的IP地址 (一)在firefox中添加该插件 步骤一:打开firefox浏览器,打开地址: https://add ...

  4. js 函数讲解

    函数 来自<JavaScript 标准参考教程(alpha)>,by 阮一峰 目录 概述 函数的声明 函数的重复声明 圆括号运算符,return 语句和递归 第一等公民 函数名的提升 不能 ...

  5. ubuntu下安装vsftpd及vsftpd配置文件不见的解决办法

    利用命令 sudo apt-get install vsftpd   //安装 进入etc文件可以找到 vsftpd.conf的配置文件 作为新手难免会弄错配置又不知道怎么办,那么可能会利用 sudo ...

  6. [转贴]infoQ VSTS被拆成5个部分,以Azure DevOps服务形式推出

    VSTS被拆成5个部分,以Azure DevOps服务形式推出 http://www.infoq.com/cn/news/2018/09/vsts-divide5parts-azuredevops?u ...

  7. C++ 查看预处理后的源文件(查看真实代码)

    gcc -E filename.cpp 会生成 filename.cpp 的预处理文件,这样就能看到宏展开后的代码,用于理解和调试宏非常有帮助.   http://www.qtdebug.com/cp ...

  8. Reverse Words in a String II

    Given an input string, reverse the string word by word. A word is defined as a sequence of non-space ...

  9. 如何在数据表中存取图片 - 回复 "三足乌" 的问题

    问题来源: http://www.cnblogs.com/del/archive/2009/05/28/1491186.html#1801853 准备工作:1.在空白窗体上添加: ClientData ...

  10. CF235C_Cyclical Quest

    很好的一个自动机的题目. 给原串,和若干个询问串.求原串里有多少个不同子串可以通过询问串循环移动得到. 有点类似求两个串的lcs,但是灵活一点. 首先我们把询问串长度扩大一倍,去掉最后一个字符.因为最 ...