1191: [HNOI2006] super hero Hero time limit:10 Sec Memory limit:162 MB
submit:1996 solved:946
[Submit] [Status] 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 Output4HINT Source
Problem: The first successful Hungarian algorithm in life!!! In fact, the specific point is to first come up directly to find a match, and if not directly matched, then by trying to change the other person's match to achieve their own matching (through a Meng Meng's recursive implementation), if the change succeeds this will be successful match, if the failure of this can not match (the subject directly interrupt match can), and then no, This algorithm explains how to write the Super stick, like one, the portal is here (in addition, to the author of the--1. You can consider changing the adjacency table optimization, especially for sparse binary plots will greatly improve the efficiency of 2. The "if (girl[j]==0 | | find (GIRL[J])) {"It is recommended that you do not use or cycle judgment, because or the loop will cause the girl[j]==0 to execute the Find (Girl[j]), which is likely to make a lot of unnecessary labor, so do you want to write separately like me? * ^_^ *)
type Point=^node; Node=RecordG:longint; Next:point; End;varI,j,k,l,m,n:longint; B:Array[0.. -] ofPoint ; F,c:Array[0.. -] ofLongint;procedureAdd (X,y:longint); varP:point; beginnew (P); P^.G:=y; P^.next:=A[x]; A[X]:=Q; New (P); P^.G:=x; P^.next:=B[y]; B[y]:=p; End;functionCheck (X:longint): boolean; varP:point; beginP:=A[x]; whileP<>Nil Do begin iff[p^.g]=0 Then beginF[P^.G]:=1; ifc[p^.g]=0 Then beginC[P^.G]:=x; Exit (TRUE); End Else ifCheck (C[P^.G]) Then beginC[P^.G]:=x; Exit (TRUE); End; End; P:=P^.next; End; Exit (FALSE); End;beginreadln (m,n); fori:=1 toN Doa[i]:=Nil; fori:=1 toM Dob[i]:=Nil; fori:=1 toN Do beginreadln (j,k); Add (I,j+1); ifK<>j ThenAdd (i,k+1); End; fori:=1 toN Do beginFillchar (F,sizeof (f),0); if not(check (i)) Then beginWriteln (i-1); Halt End; End; Writeln (n);End.
1191: [HNOI2006] super hero Hero