#K78807. Eulerian Circuit

    ID: 35168 Type: Default 1000ms 256MiB

Eulerian Circuit

Eulerian Circuit

You are given an undirected graph with N vertices and M edges. Determine whether the graph contains an Eulerian circuit.

An Eulerian circuit is a circuit that uses every edge of a graph exactly once and starts and ends at the same vertex. For an undirected graph, an Eulerian circuit exists if and only if:

  • Every vertex has an even degree, and
  • All vertices with non-zero degree are in a single connected component.

If the graph has no edges, it is considered to have an Eulerian circuit.

Your task is to read the graph from standard input and determine if the graph contains an Eulerian circuit. Print YES if it does, and NO otherwise.

inputFormat

The input is given via standard input in the following format:

N M
u1 v1
u2 v2
...
uM vM

Here, N is the number of vertices, M is the number of edges, and each of the next M lines contains two integers u and v representing an undirected edge between vertices u and v. The vertices are numbered from 1 to N.

outputFormat

Output a single line to the standard output: print YES if the graph contains an Eulerian circuit, otherwise print NO.

## sample
3 3
1 2
2 3
3 1
YES

</p>