"Hdoj 1068" Girls and Boys
The maximum independent set problem of binary graphs
Originally wanted to use the largest independent set = complement map of the largest group to do. Result timed out
Then we use the maximum independent set of the binary graph = vertex number-Two graph maximum match to do,. The VIS array is not good and super finally changed to change the right ...
Since the input map is bidirectional, the maximum match is reduced by twice times
The code is as follows:
#include <cstdlib> #include <cstdio> #include <cstring> #include <iostream> #include <vector
> Using namespace std;
Vector <int> head[555];
BOOL vis[555];
int link[555],n;
BOOL can (int p) {int i,v;
for (i = 0; i < head[p].size (); ++i) {v = head[p][i]; if (!vis[v]) {Vis[v] = true;//.
Do not change back to false after recursion otherwise it will be traversed many times as useless operation if (link[v] = = 1 | | can (LINK[V])) {link[v] = p;
return 1;
}}} return 0;
} int main () {int m,i,j,u,v,cnt;
while (~SCANF ("%d", &n)) {for (i = 0; i < n; ++i) head[i].clear ();
CNT = 0;
for (i = 0; i < n; ++i) {scanf ("%d: (%d)", &u,&m);
while (m--) {scanf ("%d", &v);
Head[u].push_back (v);
}} memset (Link,-1,sizeof (link)); for (i = 0; i < n;++i) {memset (vis,0,sizeof (VIS));
if (Can (i)) cnt++;
} printf ("%d\n", N-CNT/2);
} return 0;
}