A Cycle Problem

View as PDF

Points: 5
Time limit: 0.5s
Memory limit: 64M

Author:
Problem type

You are given a bidirectional graph. Please check whether this graph contains any cycles. A cycle is defined as a path where the starting and ending nodes are the same, contains at least one edge, and all nodes on the path are unique (except the starting and ending nodes).

Input Specification

The first line will contain two integer, .

The next lines will each contain two integers, . It is guaranteed the graph is completely connected. However, there may be multiple edges between any distinct nodes.

Output Specification

Print YES if there is a cycle, and NO otherwise.

No further constraints.

Sample Input 1

4 4
1 2
2 1
2 3
3 4

Sample Output 1

YES

Sample Input 2

4 3
1 2
2 3
2 4

Sample Output 2

NO