#P3386. 【模板】二分图最大匹配

【模板】二分图最大匹配

Description

Given a bipartite graph with nn left vertices, mm right vertices, and ee edges, find the size of its maximum matching.

The left vertices are numbered from 11 to nn, and the right vertices are numbered from 11 to mm.

Input Format

The first line contains three integers, representing nn, mm, and ee.

The next ee lines each contain two integers u,vu, v, indicating that there is an edge connecting left vertex uu and right vertex vv.

Output Format

Output a single integer on one line, representing the size of the maximum matching of the bipartite graph.

1 1 1
1 1

1
4 2 7
3 1
1 2
3 2
1 1
4 2
4 1
1 1

2

Hint

Constraints

For all test points, it is guaranteed that:

  • 1n,m5001 \leq n, m \leq 500.
  • 1e5×1041 \leq e \leq 5 \times 10^4.
  • 1un1 \leq u \leq n, 1vm1 \leq v \leq m.

The given graph is not guaranteed to be free of multiple edges.

Translated by ChatGPT 5