#P1835F. Good Graph
Good Graph
No submission language available for this problem.
Description
You are given a bipartite graph with the vertex set in the left part , in the right part , and edges connecting these two sets. We know that .
For any subset , let denote the set of all neighbors of vertices in . We say that a subset in graph is tight if . We say that graph is good if .
Your task is to verify whether the graph is good and, if so, to optimize it. If the graph is not good, find a subset such that . However, if the graph is good, your task is to find a good bipartite graph with the same set of vertices , in which , is tight in if and only if is tight in . If there are multiple such graphs, choose one with the smallest possible number of edges. If there are still multiple such graphs, print any.
The first line of the input contains two integers and (, ), separated by a single space. The number denotes the number of vertices in each of the sets and , and the number denotes the number of edges between them.
The following lines describe the edges. Each of them contains two integers and (, ), separated by a single space, indicating that there is an edge from vertex to vertex .
If the graph given in the input is not good, output one word "NO" in the first line of the output. In the second line of the output, output the number , and in the third line, output numbers , separated by single spaces. These numbers should indicate that for the set , .
However, if the graph given in the input is good, output one word "YES" in the first line of the output. In the second line of the output, output the number , indicating the number of edges in the new, also good graph . Then, in the following lines, output the edges of the graph in the same format as given in the input.
Input
The first line of the input contains two integers and (, ), separated by a single space. The number denotes the number of vertices in each of the sets and , and the number denotes the number of edges between them.
The following lines describe the edges. Each of them contains two integers and (, ), separated by a single space, indicating that there is an edge from vertex to vertex .
Output
If the graph given in the input is not good, output one word "NO" in the first line of the output. In the second line of the output, output the number , and in the third line, output numbers , separated by single spaces. These numbers should indicate that for the set , .
However, if the graph given in the input is good, output one word "YES" in the first line of the output. In the second line of the output, output the number , indicating the number of edges in the new, also good graph . Then, in the following lines, output the edges of the graph in the same format as given in the input.
Note
In the first sample test, the graph is good; thus, we are looking for an equivalent graph with the same tight sets. The only tight set is , which remains tight in the resulting graph. Moreover, no other set is tight in the resulting graph. One can prove that no graph with less than edges and the same tight sets exists.
In the second sample test, the graph is not good. Set has only one neighbour — vertex . Thus, , which is a prove that the input graph is not good.