Question: Language C programming, just use library stdio.h only Train : Circular As the mayor of Jolibi city, you need to improve the local transportation system.

Language C programming, just use library stdio.h only

Train : Circular

As the mayor of Jolibi city, you need to improve the local transportation system. One way you could do that is to construct a train route. Jolibi city has N districts, and each district has exactly one train station. You plan to construct M paths so that the final route is circular. That is, there exists a permutation p such that there is a path from district p1 to p2, from district p2 to p3, . . . , and from pn to p1 with no other paths.

You are a really busy mayor, so you asks Jojo as your personal assistant to construct the M paths for you. You need to determine whether the route constructed by Jojo is circular!

Format Input

The first line consists of two integers N and M, the number of districts and the number of paths. The next M lines each consists of two integers Ui and Vi which means that there is a path from district Ui to district Vi . Note that the path is bidirectional which means that for a given path (Ui , Vi) it is possible to travel from district Ui to district Vi and vice versa.

Format Output

Output YES if the given route is a circular road or NO if it is not.

Constraints

3 N 100

0 M N (N 1)/2

Ui 6= Vi

It is guaranteed that there will be no duplicate path in the input. The path (u, v) and (v, u) are considered as the same path.

Sample Input 1 (standard input)

4 4

3 1

4 1

3 2

2 4

Sample Output 1 (standard output)

YES

Sample Input 2 (standard input)

4 5

3 1

4 1

3 2

2 4

1 2

Sample Output 2 (standard output)

NO

Explanation

On the first sample, one of the valid circular route sequence is as follows : (3, 1, 4, 2).

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!