最大独立集: 顶点集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. Nature/Science 论文阅读笔记

    Nature/Science 论文阅读笔记 Unsupervised word embeddings capture latent knowledge from materials science l ...

  2. leetcode 148排序链表

    优先队列容器,使用小顶堆排序:timeO(nlogn) spaceO(n) /** * Definition for singly-linked list. * struct ListNode { * ...

  3. Selenium 2自动化测试实战4(引用模块)

    一.模组1.模组也叫类库或模块,引用模块 在python中,通过import….或from….import….的方式引用模块,下面引用time模块 import time print (time.ct ...

  4. Centos7 yum 源安装nginx

    一.建立nginx源 vim /etc/yum.repos.d/nginx.repo [nginx]name=nginx repobaseurl=http://nginx.org/packages/c ...

  5. 【HANA系列】【第八篇】SAP HANA XS使用Data Services查询CDS实体【二】

    公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[HANA系列][第八篇]SAP HANA XS ...

  6. 【HANA系列】SAP 【第二篇】EXCEL连接SAP HANA的方法(ODBC)

    公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[HANA系列]SAP [第二篇]EXCEL连接 ...

  7. 一本值得你反复研读的Python佳作《Python编程从0到1》

    现在的Python入门书太多太多了,究竟如何选择呢? 当然选最好的最入门的讲解最清晰的,没有那么多废话的. 现在就推荐一本<Python编程从0到1>,还带视频的,到时候跟大家一起学习沟通 ...

  8. tableau单机版安装

    参考: https://help.tableau.com/current/server-linux/zh-cn/requ.htm   先将服务器防火墙80级8850端口打开 临时关闭SELinux/防 ...

  9. Django框架中使用Echart进行统计的SQL语句

    最近想用Echart做数据统计的图形显示,数据来源是MySQL数据库,自然需要根据不同的搜索条件筛选出表中的数据,用比较多的就是时间的参数吧! 常用的mysql时间的条件进行检索的SQL语句: 数据表 ...

  10. 【Linux 驱动】简单字符设备驱动架构(LED驱动)

    本文基于icool210开发板,内核版本:linux2.6.35: 驱动代码: (1)头文件:led.h #ifndef __LED_H__ #define __LED_H__ #define LED ...