题意:给了一个有 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. 李建20181029课时整理(NOIP考点)

    历年真题 数学题: 数论(exgcd 逆元,CRT,EXCRT,快速幂,线性筛 ,杜教筛)排列组合 概率期望(什么东西) C(n,m) = 逆元? 分解质因数? Ti(大质数的类似物)思考技巧分解质因 ...

  2. CODE FESTIVAL 2017 qual B 题解

    失踪人口回归.撒花\^o^/ 说来真是惭愧,NOI之后就没怎么刷过题,就写了几道集训队作业题,打了几场比赛还烂的不行,atcoder至今是蓝名=.= 以后还是多更一些博客吧,我可不想清华集训的时候就退 ...

  3. MySQL的备份和恢复-基于LVM快照的备份(lvm-snapshot)

    MySQL的备份和恢复-基于LVM快照的备份(lvm-snapshot) 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.什么是快照卷 如上图所示,原卷和快照卷可以不一样大,因为 ...

  4. 集成maven和Spring boot的profile功能

    思路:maven支持profile功能,当使用maven profile打包时,可以打包指定目录和指定文件,且可以修改文件中的变量.spring boot也支持profile功能,只要在applica ...

  5. SCI写作经典替换词

  6. Redis五种数据结构(Windows Server)

    1.Redis的五种数据结构 这里推荐大家在命名redis的key的时候最好的加上前缀,并且使用 :来分割前缀 ,这里在使用可视化工具查看的时候就比较好区分,比如我的的前缀是 Demo:test:(一 ...

  7. python 音乐下载演示源代码

    import requests import re api = 'http://music.taihe.com/search?' header = { 'User-Agent': 'Mozilla/5 ...

  8. gdb初步窥探

    本文是通过学习左耳朵皓帝的文章,详见:http://blog.csdn.net/haoel 1.使用gdb gdb主要是用来调试c和c++程序,首先在编译前我们先把调试信息加到可执行程序当中,使用参数 ...

  9. 关于System.getProperty("java.io.tmpdir");的输出,及System.getProperty();参数

    1,首先来介绍下System.getProperty("java.io.tmpdir")输出因为这个输出有点特殊. 理论介绍:他是获取系统临时目录.可以是window的temp,l ...

  10. vb 中recordset提示对象关闭时不允许操作

    vb中执行查询后,一般要判断是否为空,只要执行的查询执行了select,都可以用rs.eof 或者 rs.recordcount来判断, 但是,如果执行的sql中加了逻辑判断,导致没有执行任何sele ...