#C5705. Contains Simple Cycle
Contains Simple Cycle
Contains Simple Cycle
You are given an undirected graph with (n) nodes and (m) edges. Your task is to determine whether the graph contains a simple cycle. A simple cycle is defined as a cycle in which only the first and the last vertices are identical, and all other vertices are distinct. More formally, a sequence of vertices (v_1, v_2, \dots, v_k, v_1) forms a simple cycle if (k \ge 3) and (v_i \neq v_j) for every (1 \le i < j \le k) (except for the equality of (v_1) and (v_k)).
inputFormat
The first line contains two integers (n) and (m), representing the number of nodes and edges, respectively. The following (m) lines each contain two integers (u) and (v), denoting an undirected edge between nodes (u) and (v).
outputFormat
Output a single line with the string "YES" if the graph contains a simple cycle; otherwise, output "NO".## sample
3 3
1 2
2 3
3 1
YES