poj1419 Graph Coloring 最大独立集(最大团)
最大独立集: 顶点集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 最大独立集(最大团)的更多相关文章
- POJ1419 Graph Coloring(最大独立集)(最大团)
Graph Coloring Time Limit: 1000MS Memor ...
- POJ1419 Graph Coloring
嘟嘟嘟 求无向图的最大独立集. 有这么一回事:最大独立集=补图的最大团. 所谓的最大团,就是一个子图,满足图中任意两点都有边. 然后ssy巨佬告诉了我一个很没有道理强的做法:随机. 每一次random ...
- POJ 1419 Graph Coloring(最大独立集/补图的最大团)
Graph Coloring Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 4893 Accepted: 2271 ...
- 【POJ】1419:Graph Coloring【普通图最大点独立集】【最大团】
Graph Coloring Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 5775 Accepted: 2678 ...
- uva193 - Graph Coloring
Graph Coloring You are to write a program that tries to find an optimal coloring for a given graph. ...
- poj 1419 Graph Coloring
http://poj.org/problem?id=1419 题意: 一张图黑白染色,相邻点不能都染黑色,最多能染几个黑色点 最大点独立集 但是图不能同构为二分图,不能用二分图匹配来做 那就爆搜吧 还 ...
- GPS-Graph Processing System Graph Coloring算法分析 (三)
HamaWhite 原创,转载请注明出处!欢迎大家增加Giraph 技术交流群: 228591158 Graph coloring is the problem of assignin ...
- UVA Graph Coloring
主题如以下: Graph Coloring You are to write a program that tries to find an optimal coloring for agiven ...
- Graph Coloring I(染色)
Graph Coloring I https://www.nowcoder.com/acm/contest/203/J 题目描述 修修在黑板上画了一些无向连通图,他发现他可以将这些图的结点用两种颜色染 ...
随机推荐
- 初始化EPT
struct eptp_bits { unsigned memory_type :; /* 0: UC uncacheable, 6: WB writeback */ unsigned pagewal ...
- 获取当前线程状态--Thread类
String msgToPrint = Thread.currentThread().getStackTrace()[3] .getMethodName(); 就是调用时的方法名. 其中使用的Thre ...
- <img>的title和alt有什么区别
1.title是全局属性之一,用于为元素提供附加的advisory information.通常当鼠标滑动到元素上的时候显示. 2.alt是<img>的特有属性,是图片内容的等价描述,用于 ...
- Reactjs之静态路由、动态路由以及Get传值以及获取
1.新增知识点 /* react路由的配置: 1.找到官方文档 https://reacttraining.com/react-router/web/example/basic 2.安装 cnpm i ...
- 三十二:数据库之SQLAlchemy.query函数可查询的数据和聚合函数
准备工作 from sqlalchemy import create_engine, Column, Integer, String, Floatfrom sqlalchemy.ext.declara ...
- sysstat功能列表
iostat:统计并报告你的设备的CPU状态和I/O状态数据.mpstat:监控和显示关于CPU的细节信息.pidstat:统计正在运行的进程/任务的CPU.内存等信息.sar:保存和报告不同资源(C ...
- Delphi中的Free和Nil和freeandnil函数
Delphi中的Free和Nil 在Delphi中释放对象资源时一般用Obj.Free(Obj为一个实例名),不过程Delphi中还有一个FreeAndNil(对象名)函数,那么用哪个好呢?Free和 ...
- elasticsearch 修改 mapping
Elasticsearch的mapping一旦创建,只能增加字段,而不能修改已经mapping的字段.但现实往往并非如此啊,有时增加一个字段,就好像打了一个补丁,一个可以,但是越补越多,最后自己都觉得 ...
- [Vuejs] 给ref赋值需要注意的问题
1.简单赋值 <div ref="refCon"></div> 访问方式: this.$refs.refCon 2.循环赋值,相同名称 <div v- ...
- JS ----- 底层原理
什么是JS JavaScript是一种基于对象的动态.弱类型脚本语言(简称JS),是一种解释型语言,和其他的编程语言不同,如java/C++等编译型语言,这些语言在代码执行前会进行通篇编译,先编译成字 ...