#C7124. Delivery Heroes and the Eulerian Circuit

    ID: 50961 Type: Default 1000ms 256MiB

Delivery Heroes and the Eulerian Circuit

Delivery Heroes and the Eulerian Circuit

The delivery heroes have an urgent task: to determine whether it is possible to plan a route that visits every road exactly once and returns to the starting point. Such a route is known as an Eulerian Circuit.

An Eulerian Circuit exists in an undirected graph if and only if:

  • All vertices with nonzero degree belong to a single connected component.
  • Every vertex has an even degree, i.e., for every vertex \(v\), \(\deg(v) \equiv 0 \pmod{2}\).

Your task is to determine, for each given city map (graph), whether an Eulerian Circuit exists. The city map is represented by intersections (vertices) and bidirectional roads (edges).

inputFormat

The input consists of multiple test cases. Each test case begins with a line containing two integers \(n\) and \(m\) where \(n\) is the number of intersections (vertices) and \(m\) is the number of roads (edges). The following \(m\) lines each contain two integers representing a bidirectional road between two intersections. The input terminates with a line containing "0 0" which should not be processed.

Example:

4 4
1 2
2 3
3 4
4 1
3 2
1 2
2 3
5 4
1 2
2 3
3 1
4 5
0 0

outputFormat

For each test case, output a single line containing either "Yes" if an Eulerian Circuit exists for the city map, or "No" otherwise.

## sample
4 4
1 2
2 3
3 4
4 1
3 2
1 2
2 3
5 4
1 2
2 3
3 1
4 5
0 0
Yes

No No

</p>