#C3882. Detect Cycle of Length Four

    ID: 47358 Type: Default 1000ms 256MiB

Detect Cycle of Length Four

Detect Cycle of Length Four

Given an undirected graph, determine whether there exists any simple cycle of exactly four vertices. A simple cycle is a cycle in which no vertex (except the starting and ending vertex) appears more than once. Formally, a cycle of length 4 is a sequence of distinct vertices \(v_1, v_2, v_3, v_4\) such that the edges \((v_1,v_2)\), \((v_2,v_3)\), \((v_3,v_4)\), and \((v_4,v_1)\) are all present in the graph.

If such a cycle exists, output "YES"; otherwise, output "NO".

inputFormat

The input is provided via standard input. The first line contains two integers \(N\) and \(M\), representing the number of vertices and the number of edges, respectively. The next \(M\) lines each contain two integers \(u\) and \(v\), representing an undirected edge between vertices \(u\) and \(v\).

outputFormat

Output a single line: "YES" if there exists a simple cycle of exactly 4 vertices; otherwise, output "NO".

## sample
5 6
1 2
2 3
3 4
4 1
1 3
2 4
YES