1191: [HNOI2006] super hero 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
1 R
0 4
3 2
3 2Sample Output4HINT Source
Solving: Two-point matching
//Meek///#include <bits/stdc++.h>#include <iostream>#include<cstdio>#include<cmath>#include<string>#include<cstring>#include<algorithm>#include<queue>#include<map>#include<Set>#include<stack>#include<sstream>#include<vector>using namespacestd;#defineMem (a) memset (A,0,sizeof (a))#definePB Push_back#defineFi first#defineSe Second#defineMP Make_pairtypedefLong Longll;Const intN =100005;Const intINF =99999999;Const intMod=1000000007;intY[n],lk[n],x,n,m;vector<int>g[n*2];intDfsintv) { for(intI=0; I<g[v].size (); i++) { if(!Y[g[v][i]]) {Y[g[v][i]]=1; if(lk[g[v][i]]==0||DFS (Lk[g[v][i])) {Lk[g[v][i]]=v; return 1; } } } return 0;}intsolve () {intans=0; for(intI=1; i<=n;i++) {mem (y); if(Dfs (i)) ans+=1; Else returnans; } returnans;}intMain () {inty; scanf ("%d%d",&m,&N); for(intI=1; i<=n;i++) {scanf ("%d%d",&x,&y); G[I].PB (x+N); G[I].PB (y+N); } printf ("%d\n", Solve ()); return 0;}
Code
Bzoj 1191: [HNOI2006] superhero hero binary match