POJ 1419 最大团问题
来源:互联网 发布:外国人吃西洋参吗 知乎 编辑:程序博客网 时间:2024/05/17 06:24
Graph Coloring
Time Limit: 1000MS Memory Limit: 10000KTotal Submissions: 3830 Accepted: 1711 Special Judge
Description
You are to write a program that tries to find an optimal coloring for a given graph. Colors are applied to the nodes of the graph and the only available colors are black and white. The coloring of the graph is called optimal if a maximum of nodes is black. The coloring is restricted by the rule that no two connected nodes may be black.
Figure 1: An optimal graph with three black nodes
Figure 1: An optimal graph with three black nodes
Input
The graph is given as a set of nodes denoted by numbers 1...n, n <= 100, and a set of undirected edges denoted by pairs of node numbers (n1, n2), n1 != n2. The input file contains m graphs. The number m is given on the first line. The first line of each graph 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
The output should consists of 2m lines, two lines for each graph found in the input file. The first line of should contain the maximum number of nodes that can be colored black in the graph. The second line should contain one possible optimal coloring. It is given by the list of black nodes, separated by a blank.
Sample Input
16 81 21 32 42 53 43 64 65 6
Sample Output
31 4 5
最大团裸题,由定理可知,最大团是最大独立集的补图,因此可以计算补图最大独立集,从而得到最大团。
代码:
/* ***********************************************Author :rabbitCreated Time :2014/3/25 20:44:48File Name :12.cpp************************************************ */#pragma comment(linker, "/STACK:102400000,102400000")#include <stdio.h>#include <iostream>#include <algorithm>#include <sstream>#include <stdlib.h>#include <string.h>#include <limits.h>#include <string>#include <time.h>#include <math.h>#include <queue>#include <stack>#include <set>#include <map>using namespace std;#define INF 0x3f3f3f3f#define eps 1e-8#define pi acos(-1.0)typedef long long ll;const int maxn=110;int n,ans,cnt,x[maxn],opt[maxn],mp[maxn][maxn];void dfs(int i){if(i>n){ans=cnt;for(int i=1;i<=n;i++)opt[i]=x[i];return;}bool flag=true;for(int j=1;j<i&&flag;j++)if(x[j]==1&&!mp[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);}}int main(){ //freopen("data.in","r",stdin); //freopen("data.out","w",stdout); int T,m,x,y; scanf("%d",&T); while(T--){ scanf("%d%d",&n,&m); memset(mp,1,sizeof(mp)); while(m--){ scanf("%d%d",&x,&y); mp[x][y]=mp[y][x]=0; } ans=cnt=0; dfs(1); cout<<ans<<endl; for(int i=1;i<=n;i++) if(opt[i])printf("%d ",i); puts(""); } return 0;}
0 0
- POJ 1419 最大团问题
- poj 1419 最大团
- poj 1419 最大团
- 【转】POJ 1419 最大团
- POJ 1419 Graph Coloring 图的着色 最大团问题
- poj 1419 Graph Coloring 【最大团】
- POJ 3692 最大团
- 【最大团】POJ 3692
- POJ 3692 最大团
- 最大团问题
- 最大团问题 MCP
- 最大团问题
- 最大团问题
- 最大团问题
- 最大团问题转载
- 最大团问题
- 最大团问题
- 最大团问题
- oracle联机热备份的原理
- Game AI resources
- [ACM] hdu 1398 Square Coins (母函数)
- Log4J基础详解及示例大全
- 减少GPU应用中的分支方法[1]
- POJ 1419 最大团问题
- 树莓派设置固定ip
- hdu 4801 Pocket Cube 四面魔方,模拟+搜索
- Java实现随机验证码功能实例
- poj 1651 区间DP
- Myeclipse配置tomcat服务器
- 如何在mysql数据库中插入中文数据
- 9.3 客户端
- C语言中基本整型数据类型