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. python learning Network Programming.py

    Socket # 用一个 Socke t表示"打开了一个网络连接" # 打开一个 Socket 需要知道目标计算机的IP地址和端口号,再指定协议类型即可. # TCP # 主动发起 ...

  2. 【CSAPP笔记】4. 汇编语言——基础知识

    程序的机器级表示 计算机能读懂是机器代码(machine code)-- 用字节序列编码的低级操作 -- 也就是0和1.编译器基于编程语言的规则.目标机器的指令集和操作系统的规则,经过一系列阶段产生机 ...

  3. 6th Alpha阶段的postmortem报告

    组名:好好学习(代组长发布)  会议重要内容记录: 1.  尝试在beta阶段实现的功能,与alpha阶段相比的优势 (1)更改软件现有的bug: 1)软件的账目只能输入,但是一旦发生失误却无法更改和 ...

  4. SQL语句查询一个数据库中的所有表

    --读取库中的所有表名 select name from sysobjects where xtype='u' --读取指定表的所有列名 select name from syscolumns whe ...

  5. 用Html5与Asp.net MVC上传多个文件

    html: <form action="/home/upload" method="post" enctype="multipart/form- ...

  6. [洛谷P4340][SHOI2016]随机序列

    题目大意:有$n(n\leqslant10^5)$个数,每两个数之间可以加入$+-\times$三种符号,$q(q\leqslant10^5)$次询问,每次询问修改一个数后,所有表达式可能的值的和 题 ...

  7. BZOJ 3731: Gty的超级妹子树

    3731: Gty的超级妹子树 Time Limit: 7 Sec  Memory Limit: 32 MBSubmit: 346  Solved: 96[Submit][Status][Discus ...

  8. 【bzoj2034】 2009国家集训队—最大收益

    http://www.lydsy.com/JudgeOnline/problem.php?id=2034 (题目链接) 题意 n个任务,每个任务只需要一个时刻就可以完成,完成后获得${W_i}$的收益 ...

  9. 面向对象高级编程(1)-使用__slots__

    使用__slots__ 正常情况下,当我们定义了一个class,创建了一个class的实例后,我们可以给该实例绑定任何属性和方法,这就是动态语言的灵活性.先定义class: >>> ...

  10. Java EE之JSP

    1.使用JSP的原因 编写Servlet代码的时候,向响应中输出HTML文档是非常不方便的. PrintWriter writer = response.getWriter(); writer.app ...