Graph (V, E) is called bipartite, if its set of vertices V can be divided to two subsets A and B so that any edge from E connects vertex from A with vertex from B.
The matching P is any subset E such that no its two edges have common vertex.
Maximum matching is a matching where the number of edges is maximal.
Find the maximal matching in the bipartite graph.
The first line contains three numbers n, m и k (1 ≤ n, m ≤ 100, 1 ≤ k ≤ 10000), where n is a number of vertices in a set A, m is a number of vertices in a set B, and k is a number of edges in a graph. Each of the next k lines contains two numbers u[i]
and v[i]
, meaning that a vertex u[i]
from set A is connected with an edge with v[i]
from set B. The vertices in sets A and B are numbered separately, starting from one. All given numbers are integers.
Print in the first line the number of edges l in maximal matching. Then print l rows, two numbers in each. The numbers a[j]
and b[j]
in the j-th row mean that matching includes the edge between vertex a[j]
of the set A and a vertex b[j]
of the set B. Printed edges must form a maximum matching.