No.1703 Much Matching
Added on 2022/09/15: The conditions in the problem statement were corrected after a flaw was pointed out.
Problem Statement
In the Kingdom of harurun, there are $N$ men numbered $1\sim N$ and $M$ women numbered $1\sim M$.
The king, harurun, wants to form as many man-woman pairs as possible.
When pairs are formed so that all of the following conditions are satisfied, what is the maximum number of pairs that can be formed?
Conditions
The same person cannot belong to multiple pairs.
Arrays $a,b$ of $Q$ elements are given. Man $x$ and woman $y$ can form a pair only when there exists an $i$ such that $a_i=x$, $b_i=y$.
Let $C_i=(x_i,y_i)$ be the $i$-th pair formed. If $i<j$, then $x_i<x_j$ and $y_i<y_j$ must hold. ($x_i$ represents a man and $y_i$ represents a woman.)
Input
$N\ M\ Q$ $a_1\ b_1$ $\vdots$ $a_Q\ b_Q$
Line $1$ contains $N$,$M$,$Q$ separated by spaces.
Lines $2\sim Q+1$ contain $a_i$,$b_i$ separated by spaces.
Constraints
$1≤N,M≤10^3$
$1≤Q≤N\times M$
$1≤a_i≤N$
$1≤b_i≤M$
$(a_i,b_i)\neq(a_j,b_j)$ when $i\neq j$
- All inputs are integers.
Output
Output the answer on one line. Print a newline at the end.
Sample
Sample 1
Input
1 1 1 1 1
Output
1
There is only one person of each. Is this kingdom going to be okay?
Sample 2
Input
3 3 2 1 2 2 3
Output
2
$C=((1,2),(2,3))$.
Sample 3
Input
3 3 3 1 2 2 3 3 1
Output
2
$C=((1,2),(2,3))$.
Note that, by the third condition, $C=((1,2),(2,3),(3,1))$ is not possible.
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。
harurun
sak