题意:给了一个有 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. MySQL服务器最大连接数的合理设置

    MySQL服务器的连接数并不是要达到最大的100%为好,还是要具体问题具体分析,下面就对MySQL服务器最大连接数的合理设置进行了详尽的分析,供您参考. 我们经常会遇见“MySQL: ERROR 10 ...

  2. 【BZOJ4444】国旗计划

    Description 题目链接 Solution 磕了3个半小时没做出来的题,就是全场崩. 首先对于一个人的答案是很好求的,显然是选择左端点在此人区间中,右端点最远(最靠右)的人作为下一个接棒人.因 ...

  3. Java: ByteBuffer在多线程中使用需要注意

    昨天我改写一个文件缓存方面程序时,用ByteBuffer替换以前用的byte[],在测试的时候抛出异常. 以前的相关代码: class A { byte[] data; ....... public  ...

  4. asp.net性能优化之使用Redis缓存(入门)

    1:使用Redis缓存的优化思路 redis的使用场景很多,仅说下本人所用的一个场景: 1.1对于大量的数据读取,为了缓解数据库的压力将一些不经常变化的而又读取频繁的数据存入redis缓存 大致思路如 ...

  5. maven pom 中的 build——resources 标签 mybatis加载mapper类及.xml文件

    转: maven 理解 2017年12月18日 15:34:31 feicongcong 阅读数:5658   版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn ...

  6. SQL记录-PLSQL条件控制

    PL/SQL条件控制   决策结构需要程序员指定一个或多个条件要计算,或由程序进行测试,如果条件被确定为真那么一条或多条语句被执行,如果要被执行的其它语句条件被确定为假,则选其它执行块. 以下是从在大 ...

  7. Django Book学习笔记(下)

    Django的Session框架 对于Django加密,大致使用这样的格式: hashtype$salt$hash 原因? 一次哈希是一次单向的加密过程,你能容易地计算出一个给定值的哈希码,但是几乎不 ...

  8. 如何使用 grunt

    1>. 首先要有nodejs环境, 至少0.8.0版本: 2>. 转到 项目文件夹下: >npm install –g grunt-cli >npm init #生成一个基本的 ...

  9. 5 THINGS TOP BUG BOUNTY HUNTERS DO DIFFERENTLY

    出处:https://www.hackerone.com/blog/5-things-top-bug-bounty-hunters-do-differently 本周,我们有幸收容了50名比利时科技学 ...

  10. Binary Representation

    Given a (decimal - e.g. 3.72) number that is passed in as a string, return the binary representation ...