Bzoj 1191 Superhero Hero Description
Now the TV station has a kind of program called superhero, the approximate process is each player to the stage to answer the host several questions, and then according to answer the question how much to obtain a different number of prizes or bonuses. Moderator questions prepared a number of topics, only when the player correctly answer a question, can enter the next question, or be eliminated. In order to increase the interest of the program and to reduce the difficulty, the host always provide players with several "tricks", such as to help the audience, or remove a number of wrong answers (choice) and so on. Here, let's change the rules a little bit. Assuming that the host has a total of M-questions, the contestants have n different "tricks". The moderator stipulates that each problem can be selected from two "tricks", and each "Ace" can only be used once. We also assume that a problem with the use of it allows the ACE, it will be able to correctly answer, smoothly into the next question. Now I came to the show, but I was too stupid, so that a problem will not do, each problem had to use the "Ace" to pass. If I knew in advance which two "tricks" can be used for each question, then can you tell me how to choose the maximum number of questions?
Input
The input file is a line of two positive integers n and m (0 < n <1001,0 < M < 1001) indicating a total of n "Ace", numbered 0~n-1, with a total of M questions.
The following M-line, two numbers per line, indicates the number of "Ace" that can be used for question M.
Note that each number of "Ace" can only be used once, the same problem of two "tricks" may be the same.
Output
The maximum number of questions the first behavior can pass p
Sample Input5 6
3 2
2 0
0 3
0 4
3 2
3 2Sample Output4———————————————————————— Split Line ————————————————————————This is a binary graph matching the naked problem, the Hungarian algorithm template problem. adjacency tables are recommended for storing edges with less time complexity.
The code is as follows:
1 /**************************************************************2 problem:11913 User:shadowland4 language:c++5 result:accepted6 time:40 Ms7 memory:1692 KB8 ****************************************************************/9 Ten#include"bits/stdc++.h" One A using namespacestd; - Const intMAXN =10100 ; - structMatch {intto, Next;}; the -Match e[maxn<<2 ] ; - inthead [MAXN], match[MAXN]; - BOOLvis [MAXN]; + - intCNT =0, ans =0 ; + A voidAdd_edge (intXinty) { ate[++cnt]. to =y; -e[CNT]. Next =head[x]; -head [x] =CNT; - } - - BOOLHungary (intx) { in for(inti = head[x]; I i =e[i]. Next) { - if(vis[i])Continue ; to inttemp =e[i]. to; +vis[I] =true ; - if(!match[temp] | |Hungary (match[temp])) { theMatch [Temp] =x; * return true ; $ }Panax Notoginseng } - return false ; the } + A intMain () { the intN, M; +memset (Match,0,sizeof(Match)); -scanf ("%d%d", &n, &M); $ for(intI=1; I<=m; ++i) { $ intx1, x2; -scanf ("%d%d", &x1, &x2); -Add_edge (i, X1), Add_edge (I, x2);//using adjacency tables to store the } - intK;Wuyi for(k=1; K<=m; ++k) { thememset (Vis,false,sizeof(VIS)); - if( !Hungary (k)) Wu Break ; - } Aboutprintf ("%d\n"K1 ) ; $ return 0 ; -}
2016-09-16 16:00:59
(end)
Bzoj 1191 Superhero Hero