Problem
Given: A positive integer and simple undirected graphs with vertices in the edge list format.
Return: For each graph, output "1" if it contains a simple cycle (that is, a cycle which doesn’t intersect itself) of length and "-1" otherwise.
Source: Algorithms by Dasgupta, Papadimitriou, Vazirani. McGraw-Hill. 2006.
问题
返回值:对于每个图,如果它包含一个长度简单的周期(即,一个不相交的周期),则输出“ 1” 否则为“ -1”。
资料来源:Dasgupta,Papadimitriou,Vazirani的算法。麦格劳-希尔。2006年。
Sample Dataset
2 4 5 3 4 4 2 3 2 3 1 1 2 4 4 1 2 3 4 2 4 4 1
Sample Output
1 -1