Roller Coaster
Time limit:1000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 19278 Accepted Submission (s): 8428
Problem Description 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, you can help calculate the maximum number of pairs can sit 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 3 1 1 1 2 1 3 2 1 2 3 3 1 0
Sample Output 3 Classic binary match for maximum match
#include <cstdio> #include <cstring> #include <algorithm> #include <iostream
> #define N 510 using namespace std;
BOOL G[n][n],y[n];
int link[n];
int n,m,k;
BOOL Find (int v) {int i;
for (i=1;i<=m;i++) {if (G[v][i]&&!y[i]) {y[i]=true; if (link[i]==-1| |
Find (Link[i])) {link[i]=v;
return true;
}}} return false;
} int main () {int i,girl,boy,sum;
while (scanf ("%d", &k)!=eof&&k) {scanf ("%d%d", &n,&m);
memset (G,0,sizeof (g));
memset (link,-1,sizeof (link));
for (i=1;i<=k;i++) {scanf ("%d%d", &girl,&boy);
G[girl][boy]=true;
} sum=0;
for (i=1;i<=n;i++) {memset (y,0,sizeof (y));
Sum+=find (i);
} cout<<sum<<endl;
} return 0; }