POJ 1419 Graph Coloring(最大独立集/补图的最大团)
| Time Limit: 1000MS | Memory Limit: 10000K | |||
| Total Submissions: 4893 | Accepted: 2271 | Special Judge | ||
Description
Figure 1: An optimal graph with three black nodes
Input
contains n and k, the number of nodes and the number of edges, respectively. The following k lines contain the edges given by a pair of node numbers, which are separated by a space.
Output
given by the list of black nodes, separated by a blank.
Sample Input
1
6 8
1 2
1 3
2 4
2 5
3 4
3 6
4 6
5 6
Sample Output
3
1 4 5
Source
题目链接:POJ 1419
模版题,熟悉一下写法和过程
代码:
#include<iostream>
#include<algorithm>
#include<cstdlib>
#include<sstream>
#include<cstring>
#include<cstdio>
#include<string>
#include<deque>
#include<stack>
#include<cmath>
#include<queue>
#include<set>
#include<map>
using namespace std;
#define INF 0x3f3f3f3f
#define CLR(x,y) memset(x,y,sizeof(x))
#define LC(x) (x<<1)
#define RC(x) ((x<<1)+1)
#define MID(x,y) ((x+y)>>1)
typedef pair<int,int> pii;
typedef long long LL;
const double PI=acos(-1.0); const int N=110; bool E[N][N];
int x[N],opt[N];
int n,m,ans,cnt,maxn,vis[N<<2]; void dfs(int i)
{
int j;
if(i>n)
{
ans=cnt;
for (j=1; j<=n; ++j)
opt[j]=x[j];
}
else
{
bool flag=true;
for (j=1; j<i&&flag; ++j)
{
if(x[j]==1&&!E[j][i])
flag=false;
}
if(flag)
{
x[i]=1;
++cnt;
dfs(i+1);
--cnt;
}
if(cnt+n-i>ans)
{
x[i]=0;
dfs(i+1);
}
}
}
void init()
{
CLR(E,true);
CLR(x,0);
CLR(opt,0);
maxn=ans=cnt=0;
CLR(vis,0);
}
int main(void)
{
int i,j,tcase,x,y;
scanf("%d",&tcase);
while (~scanf("%d%d",&n,&m))
{
init();
scanf("%d%d",&n,&m);
for (i=0; i<m; ++i)
{
scanf("%d%d",&x,&y);
E[x][y]=E[y][x]=false;
}
dfs(1);
printf("%d\n",ans);
for (i=1; i<n; ++i)
if(opt[i])
printf("%d ",i);
putchar('\n');
}
return 0;
}
POJ 1419 Graph Coloring(最大独立集/补图的最大团)的更多相关文章
- poj 1419 Graph Coloring
http://poj.org/problem?id=1419 题意: 一张图黑白染色,相邻点不能都染黑色,最多能染几个黑色点 最大点独立集 但是图不能同构为二分图,不能用二分图匹配来做 那就爆搜吧 还 ...
- poj1419 Graph Coloring 最大独立集(最大团)
最大独立集: 顶点集V中取 K个顶点,其两两间无连接. 最大团: 顶点集V中取 K个顶点,其两两间有边连接. 最大独立集=补图的最大团最大团=补图的最大独立集 #include<iostream ...
- poj 1419Graph Coloring 【dfs+补图+计算最大团+计算最大独立集 【模板】】
题目地址:http://poj.org/problem?id=1419 Graph Coloring Time Limit: 1000MS Memory Limit: 10000K Total S ...
- POJ1419 Graph Coloring(最大独立集)(最大团)
Graph Coloring Time Limit: 1000MS Memor ...
- 【poj1419】 Graph Coloring
http://poj.org/problem?id=1419 (题目链接) 题意 求一般图最大独立集. Solution 最大独立集=补图的最大团. 代码 // poj1419 #include< ...
- POJ1419 Graph Coloring
嘟嘟嘟 求无向图的最大独立集. 有这么一回事:最大独立集=补图的最大团. 所谓的最大团,就是一个子图,满足图中任意两点都有边. 然后ssy巨佬告诉了我一个很没有道理强的做法:随机. 每一次random ...
- 【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. ...
- GPS-Graph Processing System Graph Coloring算法分析 (三)
HamaWhite 原创,转载请注明出处!欢迎大家增加Giraph 技术交流群: 228591158 Graph coloring is the problem of assignin ...
随机推荐
- 【pymongo】连接认证 auth failed解决方法
故事背景: 我在虚拟机(ip:192.168.xx.xx)上建立了一个mongo的数据库,里面已经存好了内容.里面的一个database叫做 "adb", 里面有个collecti ...
- 【VirtualBox】端口转发,ssh
端口转发 VirualBox的设置 - 网络 - 端口转发 里面有主机IP.主机端口.子系统IP.子系统端口 设置后的含义是:当外部访问主机IP:主机端口后,将会把访问映射到虚拟机的子系统IP和子系统 ...
- JavaEE填空与判断
Java EE软件工程师认证考试 试题库- 填空题和选择题 一. 填空题 1. HTML网页文件的标记是__html__,网页文件的主体标记是_body__,标记页面标题的标记是__tit ...
- iOS7隐藏顶部状态栏
找到工程中的Supporting Files/工程名-info.plist 添加设置 1.status bar is initially hidden=YES 2.View Controller-ba ...
- p235习题3
- UML从需求到实现---类图(2)
上节写到了UML中的类图:UML从需求到实现---类图(1) 写完以后总觉得写的不够详细.里面很多细节没有说到.一篇文章就把强大的面向对象的类说完.当然是不可能的.这次我再补充一些关于UML中类图和类 ...
- LBS优化方案探究
方案1: 假设数据结构是这个样子的结构 那么找某个范围之内的用户,相当于: select * from tb_lbs_user where lat > lat_min and lat < ...
- 免费电子书:使用VS Online敏捷管理开源项目
今天推荐的是一本由微软出版社发布的免费电子书,涉及的话题是如何在Visual Studio Online中基于敏捷的思想来管理开源项目. 本书的几位作者(自称ALM领域的游侠),给大家分享了在一个敏捷 ...
- 【JNI】C分支
public class MainActivity extends Activity { static{ System.loadLibrary("hello"); } @Overr ...
- Grunt上手指南<转>
原文链接:http://www.hulufei.com/post/grunt-introduction 安装 如果之前有装过grunt,卸载之 npm uninstall -g grunt 安装gru ...