QOJ.ac

QOJ

Límite de tiempo: 7.0 s Límite de memoria: 2048 MB Puntuación total: 100 Hackeable ✓

#898. Maximum Bipartite Matching

Estadísticas

Given a bipartite graph, the vertices on the left side are numbered $1 \sim L$, and the vertices on the right side are numbered $1 \sim R$.

There are $M$ edges, where the $i$-th edge connects the $a_i$-th vertex on the left to the $b_i$-th vertex on the right.

Find a maximum matching for this bipartite graph.

Input

The first line of input contains three integers $L$, $R$, and $M$.

Each of the next $M$ lines contains two integers $a_i$ and $b_i$, describing an edge. Multiple edges between the same pair of vertices may exist.

Output

The first line of output contains an integer $K$, representing the size of the maximum matching.

Each of the next $K$ lines contains two integers $c_i$ and $d_i$, representing that the $c_i$-th vertex on the left is matched with the $d_i$-th vertex on the right.

If there are multiple valid solutions, you may output any one of them.

Examples

Input 1

3 2 3
1 1
2 2
3 2

Output 1

2
1 1
3 2

Subtasks

For all data, $1 \le L, R \le 2 \cdot 10^5$, $1 \le M \le 6 \cdot 10^5$, $1 \le a_i \le L$, $1 \le b_i \le R$.

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.