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