Question: many male and female students like each other and now require the largest independent subset.
Solution: As the question shows that this kind of relationship exists only between men and women, you can boldly split the diagram, because men must like women, however, women cannot have edges (like relationships ). Maximum Independent Subset = number of vertices-Maximum number of matching. Because it is a split-point diagram, We need to divide the final result by 2.
The Code is as follows:
# Include <cstdlib> # include <cstring> # include <cstdio> # include <iostream> # include <algorithm> using namespace STD; int N, Match [505]; char G [505] [505], vis [505]; bool path (int u) {for (INT I = 0; I <n; ++ I) {If (! G [u] [I] | Vis [I]) continue; vis [I] = 1; if (! (~ Match [I]) | path (Match [I]) {match [I] = u; return true ;}return false ;} int query () {// number starting from 0, initialized to-1 int ret = 0; memset (match, 0xff, sizeof (MATCH); For (INT I = 0; I <N; ++ I) {memset (VIS, 0, sizeof (VIS); RET + = path (I);} return N-(Ret> 1 );} int main () {int ID, num, C; while (scanf ("% d", & N )! = EOF) {memset (G, 0, sizeof (g); For (INT I = 0; I <n; ++ I) {scanf ("% d: (% d) ", & ID, & num); For (Int J = 0; j <num; ++ J) {scanf (" % d ", & C ); G [ID] [c] = 1; // equivalent to the split point diagram} printf ("% d \ n", query ();} return 0 ;}