"POJ 1419" Graph coloring
Maximum independent set of maximal independence set = Maximum group of complement graphs
Ideal for understanding the template problem of maximum group/maximum independent set
Set up a complement map template can need to output set point originally wanted to use the stack but found that copy comparison trouble vector with a iterator pointer loop is very convenient
The code is as follows:
#include <iostream>#include <cstdlib>#include <cstdio>#include <cstring>#include <vector>using namespace STD;BOOLmp[111][111];intlink[111][111],dp[111],MX; vector <int>S,SS;voidDfsintNintNumintStep) {inti,j,k,cnt;if(num = =0) {if(MX < Step) {s.clear (); vector<int>:: Iterator it = Ss.begin (); for(; it! = Ss.end (); ++it) S.push_back (*it); MX = step; }return; } for(i =0; i < num; ++i) {cnt =0; k = Link[step][i];if(step + n-k <= mx)return;if(step + dp[k] <= mx)return; for(j = i+1; J < num; ++J)if(Mp[link[step][j]][k]) link[step+1][cnt++] = Link[step][j]; Ss.push_back (k); DFS (n,cnt,step+1); Ss.pop_back (); }}intGetmax (intN) {intI,j,sz; MX =0; for(i = n; I >=1; -i) {sz =0; for(j = i+1; J <= N; ++J)if(Mp[i][j]) link[1][sz++] = j; Ss.push_back (i); DFS (N,sz,1); Ss.pop_back (); Dp[i] = mx; }returnMX;}intMain () {intT,n,m,u,v,i;scanf("%d", &t); while(t--) {memset(MP,true,sizeof(MP));scanf("%d%d", &n,&m); while(m--) {scanf("%d%d", &u,&v); MP[U][V] = Mp[v][u] =false; } for(i =1; I <= N; ++i) Mp[i][i] =false;printf("%d\n", Getmax (n)); vector <int>:: Iterator it = S.begin (); for(; it+1! = S.end (); ++it)printf("%d", *it);printf("%d\n", *it); }return 0;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
"POJ 1419" Graph coloring