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 题目描述 修修在黑板上画了一些无向连通图,他发现他可以将这些图的结点用两种颜色染 ...
随机推荐
- Nature/Science 论文阅读笔记
Nature/Science 论文阅读笔记 Unsupervised word embeddings capture latent knowledge from materials science l ...
- leetcode 148排序链表
优先队列容器,使用小顶堆排序:timeO(nlogn) spaceO(n) /** * Definition for singly-linked list. * struct ListNode { * ...
- Selenium 2自动化测试实战4(引用模块)
一.模组1.模组也叫类库或模块,引用模块 在python中,通过import….或from….import….的方式引用模块,下面引用time模块 import time print (time.ct ...
- Centos7 yum 源安装nginx
一.建立nginx源 vim /etc/yum.repos.d/nginx.repo [nginx]name=nginx repobaseurl=http://nginx.org/packages/c ...
- 【HANA系列】【第八篇】SAP HANA XS使用Data Services查询CDS实体【二】
公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[HANA系列][第八篇]SAP HANA XS ...
- 【HANA系列】SAP 【第二篇】EXCEL连接SAP HANA的方法(ODBC)
公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[HANA系列]SAP [第二篇]EXCEL连接 ...
- 一本值得你反复研读的Python佳作《Python编程从0到1》
现在的Python入门书太多太多了,究竟如何选择呢? 当然选最好的最入门的讲解最清晰的,没有那么多废话的. 现在就推荐一本<Python编程从0到1>,还带视频的,到时候跟大家一起学习沟通 ...
- tableau单机版安装
参考: https://help.tableau.com/current/server-linux/zh-cn/requ.htm 先将服务器防火墙80级8850端口打开 临时关闭SELinux/防 ...
- Django框架中使用Echart进行统计的SQL语句
最近想用Echart做数据统计的图形显示,数据来源是MySQL数据库,自然需要根据不同的搜索条件筛选出表中的数据,用比较多的就是时间的参数吧! 常用的mysql时间的条件进行检索的SQL语句: 数据表 ...
- 【Linux 驱动】简单字符设备驱动架构(LED驱动)
本文基于icool210开发板,内核版本:linux2.6.35: 驱动代码: (1)头文件:led.h #ifndef __LED_H__ #define __LED_H__ #define LED ...