题意:给了一个有 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. SDOI2017 R2泛做

    由于各种原因,在bzoj上我day1的题一题都没过,所以这里就直接贴loj的链接好了. D1T1 龙与地下城 中心极限定理. https://en.wikipedia.org/wiki/Central ...

  2. bzoj3884上帝与集合的正确用法

    Description   根据一些书上的记载,上帝的一次失败的创世经历是这样的: 第一天, 上帝创造了一个世界的基本元素,称做“元”. 第二天, 上帝创造了一个新的元素,称作“α”.“α”被定义为“ ...

  3. 洛谷P4135 作诗

    题意:[l,r]之间有多少个数出现了正偶数次.强制在线. 解:第一眼想到莫队,然后发现强制在线...分块吧. 有个很朴素的想法就是蒲公英那题的套路,做每块前缀和的桶. 然后发现这题空间128M,数组大 ...

  4. vue 新增时清除表单验证注意事项

    // 清除表单校验的提示 if (this.$refs['XXX']) { // 延时执行 this.$nextTick(function () { this.$refs['XXX'].clearVa ...

  5. HDU 6153 扩展kmp

    A Secret Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 256000/256000 K (Java/Others)Total ...

  6. J2EE完全手册(一)

    为了使开发者能尽快的开发企业级的应用程序,Sun在1999年推出一种基于J2SE(用于开发桌面应的Java标准版)的开发模型:J2EE,用于开发服务器应用程序与服务的Java企业版,他运行于J2EE服 ...

  7. 【问题收集·中级】关于指示器自定义图片与UUID

    博友问题: 大哥 求教一下 iOS7 能否获取到 uuid 大哥 忙不忙 iOS的加载的时候 动态旋转效果 是 图片 嘛 ? 我的回答 05:43:34hud指示器我用的是这个MBProgressHU ...

  8. Zookeeper笔记之基于zk的分布式配置中心

    一.场景 & 需求 集群上有很多个节点运行同一个任务,这个任务会有一些可能经常改变的配置参数,要求是当配置参数改变之后能够很快地同步到每个节点上,如果将这些配置参数放在本地文件中则每次都要修改 ...

  9. Mysql备份文件

  10. PowerDesigner显示Common注释列并自动赋值

    PowerDesigner中默认不显示Common注释列,可根据以下步骤显示并紫东填充Name列内容. 1.显示Common注释列 2.运行VB Script脚本自动赋值 使用Shift+Ctrl+X ...