Mirror-Symmetric Tree Graph
Time limit1sMemory limit128 MB
Decide whether a given connected graph can be formed by gluing a rooted tree to its mirrored copy at every non-root leaf.
Problem
Let T be a rooted tree, and let S be an exact copy of T. For every leaf of T except the root, identify that leaf with the corresponding leaf of S. The graph obtained this way is called a mirror-symmetric tree graph.
Given an undirected connected graph, determine whether it is a mirror-symmetric tree graph.

Input
The first line contains two integers N and M, the number of vertices and the number of edges. The vertices are numbered from 1 to N.
Each of the next M lines contains two integers x and y, describing one edge. The vertices x and y are distinct, and there is at most one edge between any pair of vertices.
Output
Print YES if the given graph is a mirror-symmetric tree graph. Otherwise, print NO.
Constraints
- 3 ≤ N, M ≤ 100,000
- 1 ≤ x, y ≤ N
- x ≠ y