Problem DESCRIPTIONRPG girls today and we go to the amusement park to play, finally can sit on the dream of the roller coaster. However, the roller coaster in each row only two seats, and there is an unwritten rule, is that every girl must find all the boys do partner and her sitting. However, each girl has their own ideas, for example, rabbit only willing and xhd or pqk do Partner,grass only willing and linle or ll do partner,princesssnow willing and water prodigal or pseudo-queer do partner. Considering the financial problems, boss Liu decided to only find partner people to ride the roller coaster, other people, hey, just stand down and watch it. Smart Acmer, can you help calculate the maximum number of pairs can be on the roller coaster?
The first line of input data is three integers k, M, N, each representing the number of possible combinations, the number of girls, and the number of males. 0<k<=1000
1<=n and m<=500. The next K-line, each line has two numbers, respectively, the female AI is willing to and boys BJ do partner. Last 0 end input.
Output for each set of data, outputs an integer that represents the maximum number of combinations that can be seated on a roller coaster.
Sample INPUT6 3 31 11 21 32 12 33 10
Sample Output3 Hungarian algorithm http://blog.csdn.net/dark_scope/article/details/8880547
1#include <iostream>2#include <cstring>3 using namespacestd;4 #defineM 5055 BOOLUsed[m],map[m][m];6 intVis[m],k,m,n,ans;7 intMain ()8 {9 BOOLFindintx);Ten while(cin>>k,k) One { ACin>>m>>N; - inti,a,b; -memset (Map,0,sizeof(map)); thememset (Vis,0,sizeof(Vis)); -ans=0; - for(i=0; i<k;i++) - { +Cin>>a>>b; -map[a][b]=1; + } A for(i=1; i<=m;i++) at { -memset (Used,0,sizeof(used));//each cycle is initialized first - if(Find (i)) ans++; - } -cout<<ans<<Endl; - } in return 0; - } to BOOLFindintX//Hungarian Algorithm + { - inti; the for(i=1; i<=n;i++) * { $ if(!used[i]&&Map[x][i])Panax Notoginseng { -used[i]=1; the if(!vis[i]| |find (Vis[i])) + { Avis[i]=x; the return true; + } - } $ } $ return false; -}
HDU 2063 roller Coaster