Roller coaster
Time limit:1000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 16791 Accepted Submission (s): 7334
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.
Input
The first line of input data is three integers k, M, N, respectively, indicating the number of possible combinations, the number of females, and the number of males. 0
#include <stdio.h> #include <string.h> int map[1500][1500];//map[i][j] Mark I and J have ambiguous ...
int vis[1500];//Marks whether the boy is visited int link[1500];//to represent whether the boys are selected int n,m,k;
bool Dfs (int x) {for (int i=1;i<=n;i++) {if (!vis[i]&&map[x][i]==1)//is not accessed, and two people have ambiguous. {vis[i]=1;//tag has been accessed if (!link[i]| |
DFS (Link[i])//Boy I was not picked or picked boys I girl can also pick other boys {link[i]=x;
return true;
}}} return false;
} int main () {while (scanf ("%d", &k)!=eof) {if (k==0) break;
scanf ("%d%d", &m,&n);
int ans=0;
memset (map,0,sizeof (map));
memset (link,0,sizeof (link));
while (k--) {int girl,boy;
scanf ("%d%d", &girl,&boy);
Map[girl][boy]=1;
} for (int i=1;i<=m;i++) {memset (vis,0,sizeof (VIS));
if (Dfs (i)) ans++; } printf ("%D\n ", ans);
} return 0; }