P27516 [洛谷] [Graph Theory and Algebraic Structures 401] Bipartite Graph Matching
提高-
题目描述

Problem Description

Given a bipartite graph with $nl$ vertices on the left side, $nr$ vertices on the right side, and $m$ edges, find a maximum matching for the graph.

Input Format

The first line contains three integers $nl$, $nr$, and $m$.

The next $m$ lines each contain two integers $u_i$ and $v_i$, indicating an edge from the $u_i$-th vertex on the left side to the $v_i$-th vertex on the right side.

Output Format

The first line contains a single integer representing the size of the maximum matching.

Sample Input and Output

Input Sample #1

2 2 3
1 1
1 2
2 1

Output Sample #1

2

Input Sample #2

2 2 2
1 1
2 1

Output Sample #2

1

Input Sample #3

15 15 30
4 14
6 1
14 7
7 8
1 12
15 8
8 10
6 10
6 2
6 12
5 1
5 14
11 10
9 9
7 12
11 13
5 9
6 9
9 1
5 8
10 13
1 13
10 3
11 7
10 8
9 5
12 13
11 6
12 15
14 4

Output Sample #3

12

Input Sample #4

15 15 40
6 10
3 10
2 2
6 5
1 3
11 7
5 8
14 2
10 5
9 15
15 13
13 14
8 10
9 10
15 1
10 2
7 1
3 8
12 3
12 10
11 4
14 11
4 13
7 11
14 15
7 13
12 7
11 6
12 15
2 9
9 9
6 13
1 9
6 15
4 4
14 12
5 4
14 5
12 9
2 10

Output Sample #4

15

Input Sample #5

15 15 2
14 1
14 2

Output Sample #5

1

Notes

For all test cases, $1 \leq nl, nr \leq 500$, and $1 \leq m \leq 2.5 \times 10^5$.

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
2 2 3 1 1 1 2 2 1
样例输出
2