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. 进阶系列(10)—— C#元数据和动态编程

    一.元数据的介绍 元数据是用来描述数据的数据(Data that describes other data).单单这样说,不太好理解,我来举个例子.下面是契诃夫的小说<套中人>中的一段,描 ...

  2. Beta 冲刺 (6/7)

    队名:Boy Next Door 燃尽图 代码写入 https://github.com/mangoqiqi/paybook/tree/master/Desktop/Web%E8%B4%A6%E5%8 ...

  3. js 对象的合并(3种方法)转载

    对象的合并 需求:设有对象 o1 ,o2,需要得到对象 o3 var o1 = { a:'a' }, o2 = { b:'b' }; // 则 var o3 = { a:'a', b:'b' } 方法 ...

  4. 第四周PSP&进度条

    团队项目PSP 一:表格     C类型 C内容 S开始时间 E结束时间 I时间间隔 T净时间(mins) 预计花费时间(mins) 讨论 讨论开发环境.工具以及技术 8:37 10:42 25 10 ...

  5. 11th 单元测试工具JUnit的学习

    1.写好一个简易的四则运算的程序 UnitTest类文件: public class UnitTest { int a; int b; int answer;//正确答案 public int plu ...

  6. php aes加密

    <?php namespace Aes; error_reporting(E_ALL); ini_set('display_errors', '1'); class Aes { /** * va ...

  7. 小程序 上啦下拉刷新window配置

    "enablePullDownRefresh": "true"   /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefres ...

  8. 使用pyquery是遇到的一个403的问题

    在网上爬虫时,本地windows下运行pyquery代码正常,但是在linux下运行时一直报错 403 Forbidden.刚开始的代码如下 from pyquery import PyQuery a ...

  9. Java容器深入浅出之Map、HashMap、Hashtable及其它实现类

    在Java中,Set的底层事实上是基于Map实现的,Map内部封装了一个Entry内部接口,由实现类来封装key-value对,当value值均为null时,key的集合就形成了Set.因此,Map集 ...

  10. command symbol & mac & emoji

    command symbol & mac & emoji how to input command symbol in mac ? https://apple.stackexchang ...