题意:给了一个有 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. 【BZOJ1021】[SHOI2008]循环的债务(动态规划)

    [BZOJ1021][SHOI2008]循环的债务(动态规划) 题面 BZOJ 洛谷 题解 感觉以前的题目都好小清新啊,我这种智商丢失的选手完全写不动. 这题看着就像一个\(dp\),并且我们发现每种 ...

  2. Mac中把光盘转存为iso文件

    因为Mac是类Unix的,因此,dd命令同样适用于Mac,那么,就很简单了,复习一下dd的用法而已 [xiaosilent@rmbp Volumes]$ drutil status Vendor Pr ...

  3. Java 8 中 Date与LocalDateTime、LocalDate、LocalTime互转

    Java 8中 java.util.Date 类新增了两个方法,分别是from(Instant instant)和toInstant()方法 // Obtains an instance of Dat ...

  4. C# 获取IIS站点及虚拟目录信息

    using System; using System.DirectoryServices; using System.Collections.Generic; using System.Text; n ...

  5. 错误 1 无法将文件“obj\Debug\XXX.exe”复制到“bin\Debug\XXX.exe”。文件“bin\Debug\XXX.exe”正由另一进程使用,因此该进程无法访问该文件

    在重新生成Windows服务的时候出现的这个问题,原因是因为你的Windows服务已经在运行了,你可以卸载掉这个服务,也可以在资源管理器里直接关闭.

  6. C语言复习---获取矩阵的对角和

    #include <stdio.h> #include <stdlib.h> #include <math.h> #define MAX 5 int main() ...

  7. SSM数据库数据导出excel

    首先,这是我对自己的需求而使用的逻辑,若有可以完美的地方方便告诉下小白. apache的poi MAVEN <dependency> <groupId>org.apache.p ...

  8. VMware vSphere克隆虚拟机

    参考资料:http://blog.csdn.net/shen_jz2012/article/details/48416771 1. 首先将你所要克隆的虚拟机关掉 2. 选择你的ESXI服务器     ...

  9. 运行fdisk命令时,弹出 bash:fdisk:command not found

    原因:命令fdisk 不在你的命令搜索路径中 第一种解决办法,将fdisk添加到你的命令搜索路径中 首先查看你当前的命令搜索路径: [root@host sbin]# echo $PATH/usr/k ...

  10. Training (deep) Neural Networks Part: 1

    Training (deep) Neural Networks Part: 1 Nowadays training deep learning models have become extremely ...