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 <k <= 1000
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. The forward Star (edge table) taught by feishen yesterday used PS here: this blog uses matrix storage: http://blog.csdn.net/acmman/article/details/38421239;# Include <stdio. h> # include <string. h> # include <stdlib. h ># include <algorithm> using namespace STD; int head [610]; int vis [610]; // whether accessed; int link [610]; // boy; int CNT; int N; struct node {int U, V, next;} edge [1100]; void add (int u, int v) {edge [CNT]. V = V; edge [CNT]. next = head [u]; head [u] = CNT ++;} int DFS (int u) {int I; for (I = head [u]; I! =-1; I = edge [I]. Next) {int x = edge [I]. V; If (! Vis [x]) // This recursion phase is not selected; {vis [x] = 1; // mark as selected; if (link [x] = 0 | DFS (link [x]) // if it is not selected or its ownership can be changed; {link [x] = u; // locate X; return 1 ;}} return 0 ;}int main () {int T, M; int U, V, I; int sum = 0; while (~ Scanf ("% d", & T) {If (t = 0) break; scanf ("% d", & N, & M ); memset (Head,-1, sizeof (head); memset (link, 0, sizeof (Link); CNT = 0; sum = 0; while (t --) {scanf ("% d", & U, & V); add (u, v) ;}for (I = 1; I <= N; I ++) {memset (VIS, 0, sizeof (VIS); If (DFS (I) sum ++;} printf ("% d \ n", sum );} return 0 ;}
Zookeeper