最大独立集: 顶点集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. C# NAudio 变声

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  2. 自定义view实现画个闪烁的心

    package com.loaderman.lovecircledemo; import android.support.v7.app.AppCompatActivity; import androi ...

  3. 谈一谈 Android 的安全机制?

    1.Android 是基于 Linux 内核的,因此 Linux 对文件权限的控制同样适用于 Android,在 Android 中每个应用都有自己的/data/data/包名 文件夹,该文件夹只能该 ...

  4. sql四种连接方式

    1.内连接(inner  join)只有两个表相匹配的行才能在结果集中显示出来2.左连接(left  join)以左表为主,左表所有的数据都会在结果集中出现,右表根据左表对应的数据显示,与左表匹配的数 ...

  5. iOS 图表工具charts之PieChartView

    关于charts的系列视图介绍传送门: iOS 图表工具charts介绍 iOS 图表工具charts之LineChartView iOS 图表工具charts之BarChartView iOS 图表 ...

  6. Python 的 Collection 库

    Collections 是 Python 内建的一个集合模块,提供了许多额外的数据类型. namedtuple namedtuple 主要用来生成可以使用名称来访问元素的数据对象,通常用来增强代码的可 ...

  7. UML_2_浅谈UML的概念和模型之UML九种图

    转载:https://my.oschina.net/zhumenzhongren/blog/667353 上文我们介绍了,UML的视图,在每一种视图中都包含一个或多种图.本文我们重点讲解UML每种图的 ...

  8. 数据测试002:利用Jmeter推送测试数据(上)

    数据测试002:利用Jmeter推送测试数据(上) 刚才用Jmeter配置一下MySQL数据库花了点时间,好在最后都解决了,注意下面几个问题: 1)没有配置  “Cannot load JDBC dr ...

  9. 【Deep Learning Nanodegree Foundation笔记】第 5 课:Logistic Regression

    Learn about linear regression and logistic regression models. These simple machine learning models a ...

  10. Linux解决Python调用Matlab函数无法导入matlab.engine问题及其他注意事项

    问题描述 Linux系统,根据matlab官方文档说明,利用Matlab中的API来实现Python调用Matlab函数.具体方法见文档: https://ww2.mathworks.cn/help/ ...