Test instructions: Zoo has n kinds of cats, m species of dogs, children like cats hate dogs, like dogs hate cats, as long as the children do not like things not, they are happy, ask their greatest happiness.
Analysis: The building is a difficult point, anyway I will not build, search the key to realize can build "contradiction side" this kind of thing. As long as the children like the things have conflict and even side, the last to find the largest independent set is the answer
/************************************************author:D arktongcreated time:2016/8/1 17:20:09File name:h du_3829.cpp*************************************************/#include<bits/stdc++.h>using namespacestd;Const intMAXN = -+Ten; Vector<int>W[MAXN];intN, M;intLEFT[MAXN];BOOLUSED[MAXN];BOOLMatchinti) { for(intj=0; J<w[i].size (); ++j)if(!Used[w[i][j]]) { intv =W[i][j]; USED[V]=true; if(! left[v]| |match (Left[v])) {Left[v]=i; return true; } } return false;}//returns the maximum number of matchesintHungary () {intres=0; Memset (left,0,sizeof(left)); for(intI=1; i<=n;++i) {memset (used,0,sizeof(used)); if(Match (i)) res++; } returnRes;}Charpeo[maxn][2][5];intMain () {intT, cas=1; intp; while(SCANF ("%d%d%d", &n, &m, &p) = =3) { //memset (w, 0, sizeof (w)); for(intI=0; i<maxn;++i) w[i].clear (); M=n=p; for(intI=1; i<=n;++i) scanf ("%s%s", peo[i][0], peo[i][1]); for(intI=1; i<=n;++i) for(intj=1; j<=n;++j)if(strcmp (peo[i][1], peo[j][0])==0) W[i].push_back (j), W[j].push_back (i); printf ("%d\n", (2*n-hungary ()) >>1); } return 0;}
hdu_3829 Cat VS Dog-Max Standalone set + build map