BZOJ 1191 HNOI 2006 superhero Hero bipartite graph maximum match

Source: Internet
Author: User

Q: You can use one of two trick answers to answer a single question. One trick can only be used once at most, and the maximum number of questions that can be answered in a row is allowed.


Idea: I first thought of the maximum matching of a bipartite graph, but I was totally confused. I think there are two trick options available for each question. It is obviously wrong to use this to split the points and create a graph ..

The correct solution is to use each question and each trick to build an edge. When a problem occurs, you can build two sides and see if you can find the augmented path. If not, you cannot answer the question correctly and output the question.


CODE:

# Include <cstdio> # include <cstring> # include <iostream> # include <algorithm> # define MAX 5010 using namespace std; int tricks, asks; int head [MAX], total; int next [MAX], aim [MAX]; int converted Red [MAX]; bool v [MAX]; inline void Add (int x, int y) {next [++ total] = head [x]; aim [total] = y; head [x] = total;} bool Hungary (int x) {for (int I = head [x]; I = next [I]) if (! V [aim [I]) {v [aim [I] = true; if (! Destination Red [aim [I] | Hungary (Destination Red [aim [I]) {destination Red [aim [I] = x; return true ;}} return false ;} int main () {cin> tricks> asks; for (int x, y, I = 1; I <= asks; ++ I) {scanf ("% d", & x, & y); x ++, y ++; Add (I, x), Add (I, y ); memset (v, false, sizeof (v); if (! Hungary (I) {cout <I-1 <endl; exit (0) ;}} cout <asks <endl; return 0 ;}


BZOJ 1191 HNOI 2006 superhero Hero bipartite graph maximum match

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.