HDU 1054 strategic game bipartite graph minimum vertex Overwrite

Source: Internet
Author: User

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 ;}

 

 

 

 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.