Want to see more problem-solving reports: http://blog.csdn.net/wangjian8006/article/details/7870410
Reprinted please indicate the source: http://blog.csdn.net/wangjian8006
Give you an undirected graph, and then color the vertices. Only black and white are allowed. The black vertices cannot be adjacent. Ask how many black vertices can be added at most.
Solution:
Vertex independence set: Set undirected graph G = <V, E>. vertex set V is a subset of V. If any two vertices in V are not adjacent, the vertex independent set called V 'is G.
This is the largest independent set.
Of course, this question can be seen as a problem of graph coloring, which can be directly searched.
Another theorem is the largest group of largest independent sets = supplementary graphs.
Largest group = the largest independent set of the supplementary Graph
Hdu1530 largest group
/*Memory 212KTime 16MS*/#include <iostream>using namespace std;#define MAXV 110int n,m;int map[MAXV][MAXV],vis[MAXV],tmp[MAXV];int ans,cnt;void dfs(int x){int i;if(x>n){for(i=1;i<=n;i++) tmp[i]=vis[i];ans=cnt;return ;}int flag=1;for(i=1;i<x;i++){if(vis[i] && map[x][i]){flag=0;break;}}if(flag){vis[x]=1,cnt++;dfs(x+1);cnt--,vis[x]=0;}if(cnt+n-x>ans){vis[x]=0;dfs(x+1);}}int main(){int a,b,i,flag;int Case;scanf("%d",&Case);while(Case--){memset(map,0,sizeof(map));scanf("%d%d",&n,&m);while(m--){scanf("%d%d",&a,&b);map[a][b]=map[b][a]=1;}ans=cnt=0;dfs(1);printf("%d\n",ans);flag=0; for (i=1;i<=n;i++){ if(tmp[i]){ if(flag) printf(" "); printf("%d",i); flag=1; }}printf("\n");}return 0;}