Maximum matching#1989

Maximum matching

1 second
128 megabytes
Medium

A graph G = (V, E) is called bipartite if its set of vertices can be divided into two subsets and such that every edge from connects a vertex from with a vertex from .

A matching is a subset of such that no two edges from share a common vertex.

A maximum matching is a matching that contains the largest possible number of edges.

Find the maximum matching in the given bipartite graph.

Input

The first line contains three integers , , and (1 \le n, m \le 100,\ 1 \le k \le 10000), where is the number of vertices in set , is the number of vertices in set , and is the number of edges in the graph.

Each of the following lines contains two integers u_i and v_i, denoting that vertex u_i from set is connected with vertex v_i from set . Vertices in sets and are numbered independently, starting from one.

All input numbers are integers.

Output

In the first line, output the number — the number of edges in the maximum matching.

Then output lines, each containing two integers and : a vertex from set and the corresponding vertex from set in the matching.

The printed edges must form a maximum matching.

Examples

Example 1

Loading
Loading