Roller coaster
RPG 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 Input
6 3 31 11 21 32 12 33 10
Sample Output
3
————————————————————————————————————————————————————————————————————
A template problem that matches a binary graph. Hungarian algorithm.
————————————————————————————————————————————————————————————————————
1#include <cstdio>2#include <iostream>3#include <cstring>4#include <algorithm>5 6 using namespacestd;7 Const intmaxn=1010;8 intn,m,k;9 intHead[maxn],js;Ten structEdge One { A intU,v,next; - }E[MAXN]; - intLINK[MAXN]; the BOOLVIS[MAXN]; - voidInit () - { -Memset (Head,0,sizeof(head)); +Memset (E,0,sizeof(e)); -js=0; +memset (Link,0,sizeof(link)); A } at voidAddage (intUintv) - { -e[++js].u=u;e[js].v=v; -e[js].next=head[u];head[u]=JS; - } - BOOLDfsintu) in { - for(intI=head[u];i;i=e[i].next) to { + intv=e[i].v; - if(!Vis[v]) the { *vis[v]=1; $ if(link[v]==0||DFS (Link[v]))Panax Notoginseng { -link[v]=u; the return 1; + } A } the } + return 0; - } $ intMain () $ { - while(SCANF ("%d%d%d", &k,&m,&n) = =3) - { the init (); - for(intU,v,i=0; i<k;i++)Wuyi { thescanf"%d%d",&u,&v); -Addage (u,m+v); Wu } - intans=0; About for(intI=1; i<=m;i++) $ { -memset (Vis,0,sizeof(Vis)); - if(Dfs (i)) ans++; - } Aprintf"%d\n", ans); + } the return 0; -}
View Code
HDU2063 Roller coaster