Question
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
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 1 (standard input)
4 3
3 1
2 3
4 3
Sample Output 1 (standard output)
YES
Sample Input 2 (standard input)
4 2
3 1
2 3
Sample Output 2 (standard output)
NO
Explanation
On the first sample, one of the valid star shape sequence is as follows : (3, 1, 4, 2).
NOTE: USE C LANGUAGE, USE stdio.h library(MUST) and string.h if needed. (DONT USE stdlib.h and algorithm library)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started