問題一覧 > 通常問題

No.1703 Much Matching

レベル : / AI推定難易度 : 800 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (解説公開後に AC するまで非表示) / 解いたユーザー数 123
作問者 : harurun / テスター : sak
お気に入りにしたユーザー ProblemId : 6929 / 自分の提出
問題文最終更新日: 2022-09-15 11:34:45
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
yukicoder contest 317 (順位表) の他の問題:

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もしくは右上の雲マークをクリックしてアカウントを作成してください。