Ancient Greek isomorphism
It is well known that the favourite graph of Zeus is a grid (namely, a rectangular grid graph) n * m, i.e. an undirected graph of n * m vertices and n * (m - 1) + (n - 1) * m edges, which can be represented as a grid with n rows and m columns so that each vertex is connected to neighbouring vertices.
Denote by (i, j) the vertex at the intersection of the i-th row and j-th column. Formally, in the graph there are edges between (i, j) and (i + 1, j) for all 1 ≤ i < n, 1 ≤ j ≤ m, and edges between (i, j) and (i, j + 1) for all 1 ≤ i ≤ n, 1 ≤ j < m.
(The illustration shows an example of a grid graph 6 * 5)
And surprisingly, it turned out that the beloved graph of Poseidon is also non-oriented, it also contains n * m vertices and n * (m - 1) + (n - 1) * m edges, and also does not contain loops and multiple edges. The vertices of his graph are numbered with integers from 1 to n * m.
Poseidon became interested, but maybe his and Zeus' graph are exactly the same (isomorphic)?
Formally, he wondered if its possible to find a unique correspondence between the vertices of the Poseidon graph and the vertices of the Zeus graph (that is, each vertex of the Poseidon graph should be associated with exactly one vertex of the Zeus graph so that each vertex of the Zeus graph was mapped to exactly one vertex of the Poseidon graph) so that two vertices are adjacent in one of these graphs if and only if their corresponding vertices are adjacent in another graph.
Help Poseidon with his difficult task, check his graph and the graph of Zeus for isomorphism!
Input
First line contains two integers n and m (2 ≤ n, m, n * m ≤ 2 * 10^5
), indicating the size of the grid.
In the next n * (m - 1) + (n - 1) * m lines the description of the edges Poseidon's graph is given. The i-th line contains two integers u[i]
and v[i]
(1 ≤ u[i]
, v[i]
≤ n * m, u[i]
≠ v[i]
), denoting an edge connecting the corresponding vertices.
It is guaranteed that the Poseidon's graph does not contain multiple edges.
Output
If the graphs of Poseidon and Zeus are isomorphic, print "Yes". Otherwise, print "No".
Sample
The graph from the second example is shown in the picture: