Question: C Programming Language ( Code With C Programming Language) Problem Title : Star Train As the mayor of Jolibi city, you need to improve the

C Programming Language ( Code With C Programming Language)

Problem Title : Star Train

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 has a star shape. That is, there exists a permutation p such that there is a path from district p1 to p2, from district p1 to p3, ....., and from district p1 to pn with no other paths.

You are a really busy mayor, so you asks Jojo as your personal assistant to construct the M routes for you. You need to determine whether the routes constructed by Jojo has a star shape!

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 has a star shape or NO if it is not.

Constraints

  • 3 N 100
  • 0 M N (N 1)/2
  • Ui 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 & Output 1 (Standard Input & Output)

4 3 3 1 2 3 4 3 YES

Sample Input & Output 2 (Standard Input & Output)

4 2 3 1 2 3 NO

Explanation

On the first sample, one of the valid star shape 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!