Maximum matching
A graph is called bipartite if its vertex set can be divided into two subsets and such that every edge in connects a vertex from to a vertex from .
A matching is any subset of such that no two edges in this subset share a common vertex.
A maximum matching is a matching that contains the largest number of edges.
Find a maximum matching in the given bipartite graph.
Input
In the first line, three numbers , and are given, 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 next lines contains two integers and , indicating that vertex from set is connected to vertex from set . The vertices in sets and are numbered independently, starting from one. All input numbers are integers.
Output
In the first line, print the number of edges in the maximum matching. Then print lines, each containing two numbers: and , where is a vertex from set , and is the corresponding vertex from set in the matching. The printed edges must form a maximum matching.