最大独立集: 顶点集V中取 K个顶点,其两两间无连接。

最大团: 顶点集V中取 K个顶点,其两两间有边连接。

最大独立集=补图的最大团
最大团=补图的最大独立集

#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std; int mp[][],mark1[],mark2[];
int n,m;
int cnt,maxx; void dfs(int x)
{
if(x>n) // 如果枚举了所有的节点
{
maxx=cnt;
memcpy(mark1,mark2,sizeof(mark2)); // 用一个更大的极大团替代原有的极大团
return;
}
int flag=true;
for(int i=; i<x; i++) // 检测新加入的点是否到团中的其他节点都存在一条边
{
if(mark2[i] && !mp[i][x])
{
flag=false;
break;
}
}
if(flag) // 如果该节点满足在这个团中
{
mark2[x]=,cnt++; // 该节点被加入到完全子图中去
dfs(x+);
mark2[x]=,cnt--;
}
if (cnt+n-x>maxx) // 跳过x节点进行搜索同时进行一个可行性判定
dfs(x+);
} int main()
{
int T;
scanf("%d",&T);
while(T--)
{
scanf("%d%d",&n,&m);
memset(mark1,,sizeof(mark2));
memset(mark2,,sizeof(mark2));
maxx=cnt=;
for(int i=; i<; i++)
fill(mp[i],mp[i]+,);
for(int i=; i<=m; i++)
{
int a,b;
scanf("%d%d",&a,&b);
mp[a][b]= mp[b][a]=;
}
dfs();
printf("%d\n",maxx);
int k=;
for(int i=; i<=n; i++)
{
if(mark1[i])
{
if(k==)
{
printf("%d",i);
k=;
}
else
printf(" %d",i);
}
}
puts("");
}
return ;
}

poj1419 Graph Coloring 最大独立集(最大团)的更多相关文章

  1. POJ1419 Graph Coloring(最大独立集)(最大团)

                                                               Graph Coloring Time Limit: 1000MS   Memor ...

  2. POJ1419 Graph Coloring

    嘟嘟嘟 求无向图的最大独立集. 有这么一回事:最大独立集=补图的最大团. 所谓的最大团,就是一个子图,满足图中任意两点都有边. 然后ssy巨佬告诉了我一个很没有道理强的做法:随机. 每一次random ...

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

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

  4. 【POJ】1419:Graph Coloring【普通图最大点独立集】【最大团】

    Graph Coloring Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 5775   Accepted: 2678   ...

  5. uva193 - Graph Coloring

    Graph Coloring You are to write a program that tries to find an optimal coloring for a given graph. ...

  6. poj 1419 Graph Coloring

    http://poj.org/problem?id=1419 题意: 一张图黑白染色,相邻点不能都染黑色,最多能染几个黑色点 最大点独立集 但是图不能同构为二分图,不能用二分图匹配来做 那就爆搜吧 还 ...

  7. GPS-Graph Processing System Graph Coloring算法分析 (三)

        HamaWhite 原创,转载请注明出处!欢迎大家增加Giraph 技术交流群: 228591158     Graph coloring is the problem of assignin ...

  8. UVA Graph Coloring

    主题如以下: Graph Coloring  You are to write a program that tries to find an optimal coloring for agiven ...

  9. Graph Coloring I(染色)

    Graph Coloring I https://www.nowcoder.com/acm/contest/203/J 题目描述 修修在黑板上画了一些无向连通图,他发现他可以将这些图的结点用两种颜色染 ...

随机推荐

  1. 线性回归和正则化(Regularization)

    python风控建模实战lendingClub(博主录制,包含大量回归建模脚本和和正则化解释,2K超清分辨率) https://study.163.com/course/courseMain.htm? ...

  2. 使用relo

    安装好插件以后,选择一个工程,右键点击relo connection(如果已经连接了就不需要点击).点击navigate,open relo session,选择一个文件,可以打开这个文件的类图,点击 ...

  3. OpenFlow Switch 1.3 规范

    目录 文章目录 目录 OpenFlow 架构 OpenFlow 标准和规范 OpenFlow 的端口(Port) OpenFlow 的流表(Flow Table) OpenFlow 的组表(Group ...

  4. RedHat 5下安装gcc编译环境的具体步骤

    RedHat 5下安装gcc编译环境的具体步骤 在RHEL5系统中默认不安装linux系统中的开发编译环境(gcc),此软件包安装时依赖其他包较多 在以前使用RHEL4时可以通过如下命令安装: rpm ...

  5. django 如何传递id 参数

    urls.py  注意这里的bid

  6. SVN的使用和问题解决方法总结

    添加仓库之类的很简单,这里就不说了哈...不会的可以问问我,当然百度再快了..嘿嘿 1.从服务器Check Out代码: 2.提交代码: 3.你是不是今天和我一样纠结如何删除已经上传SVN的内容,其实 ...

  7. 部署php程序报错解决---TP框架

    1.TP框架中 出现如下错误: 访问网站 http://192.168.0.204/ STORAGE_WRITE_ERROR_:./Runtime/Cache/Home/51620d75af91aa7 ...

  8. 【内部】Fiddler设置代理请求的方式

    1.2 打开Fiiddler,设置如图步骤: 3.添加规则: 4.这里选择第三个选项: 5.选中^开始,空格结束的如图内容.复制你要代理的地址.如:http://wap.cmread.com/nap/ ...

  9. 网格UV展开

    原文链接 UV展开是什么 参数曲面的参数域变量一般用UV字母来表达,比如参数曲面F(u,v).所以一般叫的三维曲面本质上是二维的,它所嵌入的空间是三维的.凡是能通过F(u,v)来表达的曲面都是参数曲面 ...

  10. RPC架构下org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)

    一.调用后台接口报错 网上有很多作者列出大部分原因: 1.实体类名对应配置文件名或者路径不一致 2.spring扫描路径不全 但是本人使用的是mtbatis逆向工程生成的实体类.接口与配置文件,所以不 ...