Cycles in the graph
Medium
Execution time limit is 1 second
Runtime memory usage limit is 128 megabytes
Given an undirected graph without loops and multiple edges. Determine whether there are cycles in the graph, and, if so, find the vertex with the smallest number belonging to at least one of the cycles.
Input
The first line contains two integers n and k (1 ≤ n ≤ 10^5
, 0 ≤ k ≤ 10^5
) - the number of vertices and edges in the graph. Followed by k lines, each contains a pair of distinct integers a, b (1 ≤ a, b ≤ n) which means that there is an edge in the graph between the vertices a and b. Each pair of a, b does not occur more than once.
Output
If the graph contains no cycles, print a single word No. Otherwise, print in the first line Yes and in the next line print the smallest number of vertex belonging to at least one cycle.
Examples
Input #1
Answer #1
Submissions 3K
Acceptance rate 10%