Hdu 2063 roller coaster-bipartite graph Hungary Algorithm
A B C D E F G H IB-roller coastersTime Limit:1000 MSMemory Limit:32768KB64bit IO Format:% I64d & % I64u Submit Status
Description
RPG girls went to the playground with everyone today and finally got on the coveted roller coaster. However, there are only two seats in each row of the roller coaster, and there is an unwritten rule, that is, every girl must find a boy as a partner and sit with her. However, every girl has her own ideas. For example, Rabbit is only willing to be a partner with XHD or PQK. Grass is only willing to be a partner with linle or LL, princessSnow is willing to be a partner with the water prodigal son or pseudo cool. Considering the funding issue, boss Liu decided to let the partner find a ride on the roller coaster. Other people, hey, just stand and watch it. Smart Acmer, can you help calculate how many combinations can ride on a roller coaster?
Input
The first line of the input data is a three integer K, M, N, indicating the number of possible combinations, the number of girls, and the number of boys. 0 1 <= N and M <= 500. In the next K rows, each row has two numbers, indicating that female Ai is willing to be partner with boys' Bj. The last 0 end input.
Output
For each group of data, an integer is output, indicating the maximum number of combinations that can be used on a roller coaster.
Sample Input
6 3 31 11 21 32 12 33 10
Sample Output
3
ACcode:
# Include
# Include
# Include
Using namespace std; int line [501] [501], boy [501], used [501]; int n, m; bool find (int x) {for (int I = 1; I <= m; I ++) // traverse all selected boys {if (line [x] [I] &! Used [I]) // x girls have a crush on I boys and I boys are not occupied by other girls {used [I] = true; /// mark the boy as if (boy [I] = 0 | find (boy [I]) /// if I has no other girl selected or his/her attribution can be changed to {boy [I] = x; // return true if the boy belongs to X ;}}} return false;} int main () {int k, x, y, sum; while (scanf ("% d", & k, & n, & m), k) {sum = 0; // The total number of memset (line, 0, sizeof (line) records that match the question. memset (boy, 0, sizeof (boy); for (int I = 0; I