Detect a Cycle in an Undirected Graph

MEDIUM · C · 2000ms

A junior admin suspects a faulty configuration created a routing loop — Rakib must check if the network contains any cycle at all. Given an undirected graph with N nodes and M edges, print "YES" if it contains a cycle, else "NO".

Input

Line1: N M. Next M lines: u v.

Output

"YES" or "NO".

Constraints

1 ≤ N ≤ 10^5, 0 ≤ M ≤ 2×10^5

Sample Input

4 4
1 2
2 3
3 4
4 1

Sample Output

YES
main.c
Loading editor…

Write C, then Run (custom I/O) or Submit (sample tests). ⌘/Ctrl+Enter submits.

Detect a Cycle in an Undirected Graph · DIU ContestHub