#K11416. Eulerian Circuit Checker
Eulerian Circuit Checker
Eulerian Circuit Checker
You are given an undirected graph defined by vertices and edges. Your task is to determine whether the graph contains an Eulerian Circuit. A graph has an Eulerian circuit if and only if every vertex with a nonzero degree is connected and each of these vertices has an even degree. In mathematical terms, for every vertex \( v \) with degree \( d(v) \), an Eulerian circuit exists if \( d(v) \equiv 0 \pmod{2} \) for all \( v \) and the subgraph consisting of vertices with nonzero degree is connected.
The input consists of one or more datasets. Each dataset starts with a line containing two integers \( n \) and \( m \), where \( n \) is the number of vertices (labeled from 1 to \( n \)) and \( m \) is the number of edges in the graph. The next \( m \) lines each contain two integers \( u \) and \( v \), representing an undirected edge between vertices \( u \) and \( v \). The input terminates with a line containing a single 0, which should not be processed.
inputFormat
The input is read from stdin and consists of multiple datasets. Each dataset is formatted as follows:
n m u1 v1 u2 v2 ... um vm
The end of input is indicated by a single line containing the number 0.
outputFormat
For each dataset, print a single line to stdout containing either "YES" if the graph contains an Eulerian circuit, or "NO" otherwise.
## sample3 3
1 2
2 3
3 1
0
YES
</p>