2023 Winter Waterloo Local Contest, Problem D
BaoBao just learned how to use a data structure called link-cut tree to find cycles in a graph and decided
to give it a try. BaoBao is given an undirected graph with
A simple cycle is a subgraph of the original graph containing
Input Specification
There are multiple test cases. The first line of the input contains an integer
The first line contains two integers
For the following
It's guaranteed that neither the sum of
Output Specification
For each test case output one line. If there are no simple cycles in the graph output -1
;
Otherwise output
Please, DO NOT output extra spaces at the end of each line, or your answer may be considered incorrect!
Sample Input
2
6 8
1 2
2 3
5 6
3 4
2 5
5 4
5 1
4 2
4 2
1 2
4 3
Sample Output
2 4 5 6
-1
Explanation for Sample
The first sample test case is shown below. The integers beside the edges are their indices (outside the
parentheses) and lengths (inside the parentheses). The simple cycle with the smallest length consists of
edges
Comments