To solve this problem, you must master the following two points:
1. minimum vertex overwrite of a bipartite graph = maximum matching of a bidirectional bipartite graph/2.
2. Using Vector in STL, you can easily create an adjacent table for graph storage. Push_back () and clear () operations are mainly used.
3. scanf () and printf () functions can easily implement the input and output in the question. For details, see the code.
AC code: 625 Ms
# Include <iostream> # include <vector> using namespace STD; const int max = 1500; vector <int> map [Max]; // bool map [Max] [Max]; bool used [Max]; int link [Max]; int N; void preclear () {for (INT I = 0; I <n; I ++) map [I]. clear ();} void storemap () // store the Binary Graph {preclear (); int I, j, row, Col, num; memset (MAP, false, sizeof (MAP); For (j = 0; j <n; j ++) {scanf ("% d :( % d)", & Row, & num ); for (I = 0; I <num; I ++) {scanf ("% d", & col); // map [row] [col] = true; // map [col] [R Ow] = true; // adjacent table, bidirectional map [row]. push_back (COL); map [col]. push_back (ROW) ;}} bool can (INT t) // determine whether the augmented path {int TMP; For (INT I = 0; I <map [T]. size (); I ++) {TMP = map [T] [I]; If (! Used [TMP]) {used [TMP] = true; If (link [TMP] =-1 | can (link [TMP]) {link [TMP] = T; return true ;}} return false;} int maxmatch () {int num = 0; memset (link, 0xff, sizeof (Link )); for (INT I = 0; I <n; I ++) // find the augmented path from each left vertex {memset (used, false, sizeof (used )); if (CAN (I) num ++;} return num;} int main () {While (scanf ("% d", & n) = 1) {storemap (); printf ("% d \ n", maxmatch ()/2);} return 0 ;}