
ZOJ Problem Set  3321
Your task is so easy. I will give you an undirected graph, and you just need to tell me whether the graph is just a circle. A cycle is three or more nodes V_{1}, V_{2}, V_{3}, ... V_{k}, such that there are edges between V_{1} and V_{2}, V_{2} and V_{3}, ... V_{k} and V_{1}, with no other extra edges. The graph will not contain selfloop. Furthermore, there is at most one edge between two nodes. Input There are multiple cases (no more than 10). The first line contains two integers n and m, which indicate the number of nodes and the number of edges (1 < n < 10, 1 <= m < 20). Following are m lines, each contains two integers x and y (1 <= x, y <= n, x != y), which means there is an edge between node x and node y. There is a blank line between cases. Output If the graph is just a circle, output "YES", otherwise output "NO". Sample Input 3 3 1 2 2 3 1 3 4 4 1 2 2 3 3 1 1 4 Sample Output YES NO Author: LIN, Yue Source: The 10th Zhejiang University Programming Contest 