题意:给了一个有 n 个点 m 条边的无向图,要求用黑、白两种色给图中顶点涂色,相邻的两个顶点不能涂成黑色,求最多能有多少顶点涂成黑色。图中最多有 100 个点

该题是求最大独立集团  最大团点的数量=补图中最大独立集点的数量  ----->最大独立集团的数量 =补图中最大团点的数量  是完全对称的

并且要打印出点

#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std; #define N 110 int n;
int mp[N][N];
int ans;
int alt[N][N];
int Max[N];
int path[N];
int anspath[N]; bool dfs(int cur,int tot)//cur是s1集合的个数
{
if(==cur)
{
if(tot>ans)
{
ans=tot;
for(int i=;i<=tot;i++)anspath[i]=path[i];
return true;
}
return false;
} for(int i=;i<cur;i++)
{
if( tot+cur-i<=ans )return false;
int u=alt[tot][i];
if( Max[u]+tot<=ans )return false;
int next=;
for(int j=i+;j<cur;j++)
if(mp[u][ alt[tot][j] ])alt[tot+][next++]=alt[tot][j];
path[tot+]=u;
if(dfs(next,tot+)) return ;
}
return ;
} int maxclique(void)
{
ans=; memset(Max,,sizeof(Max));
for(int i=n-;i>=;i--)
{
int cur=;
path[]=i;
for(int j=i+;j<n;j++)if(mp[i][j])alt[][cur++]=j;//1为s1集合
dfs(cur,);
Max[i]=ans;
}
return ans;
} int main()
{
int cas;
cin>>cas;
while(cas--)
{
int m;
memset(mp,,sizeof mp);
scanf("%d%d",&n,&m);
while(m--)
{
int a,b;
scanf("%d%d",&a,&b);
mp[a-][b-]=mp[b-][a-]=; }
int k=maxclique();
printf("%d\n",k);
for(int i=;i<=k;i++)
{
printf("%d",anspath[i]+);
if(i==k)printf("\n");
else printf(" ");
}
}
return ;
}

Garph Coloring的更多相关文章

  1. Codeforces Round #369 (Div. 2)---C - Coloring Trees (很妙的DP题)

    题目链接 http://codeforces.com/contest/711/problem/C Description ZS the Coder and Chris the Baboon has a ...

  2. CF149D. Coloring Brackets[区间DP !]

    题意:给括号匹配涂色,红色蓝色或不涂,要求见原题,求方案数 区间DP 用栈先处理匹配 f[i][j][0/1/2][0/1/2]表示i到ji涂色和j涂色的方案数 l和r匹配的话,转移到(l+1,r-1 ...

  3. Codeforces Round #369 (Div. 2) C. Coloring Trees DP

    C. Coloring Trees   ZS the Coder and Chris the Baboon has arrived at Udayland! They walked in the pa ...

  4. CodeForces #369 C. Coloring Trees DP

    题目链接:C. Coloring Trees 题意:给出n棵树的颜色,有些树被染了,有些没有.现在让你把没被染色的树染色.使得beauty = k.问,最少使用的颜料是多少.   K:连续的颜色为一组 ...

  5. CodeForces 149D Coloring Brackets

    Coloring Brackets time limit per test: 2 seconds memory limit per test: 256 megabytes input: standar ...

  6. C. Coloring Trees DP

    传送门:http://codeforces.com/problemset/problem/711/C 题目: C. Coloring Trees time limit per test 2 secon ...

  7. codeforces 711C C. Coloring Trees(dp)

    题目链接: C. Coloring Trees time limit per test 2 seconds memory limit per test 256 megabytes input stan ...

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

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

  9. URAL 1080 Map Coloring(染色)

    Map Coloring Time limit: 1.0 secondMemory limit: 64 MB We consider a geographical map with N countri ...

随机推荐

  1. 【Revit API】墙体分割

    Revit中没有分割墙体的直接方法,一般采用调整原墙体的长度,再复制自身,调整复制体的长度.话不多说,直接上代码 public static void WallCopy(Document doc, X ...

  2. 【转】Keil ARM开发 error L6236E错误解决

    顺利创建了第一个Keil工程却发现不能完成链接,出现了一个下面这样的报错: .\Objects\demo_simple.sct(7): error: L6236E: No section matche ...

  3. 【AGC006E】 Rotate 3x3

    Description ​ 题目链接 Solution ​ 显然每一列只能一起动,乱动则无解. ​ 对原网格按列黑白染色,显然每一列数只能在相同颜色之间交换,乱动则无解. ​ 之后考虑构造方案. ​ ...

  4. AIO + ByteBufferQueue + allocateDirect 终于可以与NIO的并发性能达到一致。

    看到这个标题,你可能会惊讶,相比NIO,AIO不就是为了在高并发的情况下代替NIO的吗? 是的,没错,但是在并发不高的情况下,AIO的性能表现很多时候还不如NIO. 在一台机子上用ab进行并发压力测试 ...

  5. 生成器python

    一.列表生成式 需求:看列表[0, 1, 2, 3, 4, 5, 6, 7, 8, 9],我要求你把列表里的每个值加1,你怎么实现?你可能会想到2种方式 >>> a [0, 1, 2 ...

  6. Swift学习笔记2

    1.函数参数都有一个外部参数名(external parameter name)和一个局部参数名(local parameter name).外部参数名用于在函数调用时标注传递给函数的参数,局部参数名 ...

  7. [HAOI2008]移动玩具(状压&带权二分图)

    题目描述 • 一个 4 × 4 的 0/1 矩阵 • 每次可以交换相邻两个元素 • 求从初始状态到目标状态的最小交换次数 输入格式 前四行,每行一个长为 4 的 0/1 字符串,描述初始状态. 后四行 ...

  8. Git常见错误处理

      如果输入$ Git remote add origin git@github.com:djqiang(github帐号名)/gitdemo(项目名).git  提示出错信息:fatal: remo ...

  9. LVTTL与LVCMOS区别

    TTL电平的VIH/VIL一般是2V/0.8V,VOH/VOL一般是 2.4V/0.4V,不论是3.3V还是5V的TTL都一样的:CMOS的VIH/VIL一般是70%VCC/30%VCC,VOH/VO ...

  10. 如何生成能在没有安装opencv库及vs2010环境的电脑上运行的exe文件

    项目基本算法已经完成,甲方需要一个可以运行的demo.目前,程序能在自己的电脑上正常运行.移植到其他win7系统上,运行失败. 寻找各种解决办法,baidu找到两个办法: 1.使用静态链接的方法,这种 ...