Link-Cut Tree

시간 제한2초메모리 제한1024 MB

요약
간선 i의 길이가 2^i인 무향 그래프에서 길이가 가장 짧은 단순 사이클의 간선 번호를 출력하고, 사이클이 없으면 -1을 출력한다.
난이도

어려움10점 중 8점

유형
그래프, 최소 신장 트리, 그리디, 유니온 파인드
정답자
아직 제출이 없습니다

문제

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 nn vertices and mm edges, where the length of the ii-th edge equals 2i2^i. She needs to find a simple cycle with the smallest length.

A simple cycle is a subgraph of the original graph containing kk (3≤k≤n3 ≤ k ≤ n) vertices a_1,a_2,⋯ ,a_ka\_1, a\_2, \cdots , a\_k and kk edges such that for all 1≤i≤k1 ≤ i ≤ k there is an edge connecting vertices a_ia\_i and a_(i mod k)+1a\_{(i \bmod k)+1} in the subgraph. The length of a simple cycle is the total length of the edges in the cycle.

입력

There are multiple test cases. The first line of the input contains an integer TT indicating the number of test cases. For each test case:

The first line contains two integers nn and mm (3≤n≤1053 ≤ n ≤ 10^5, 1≤m≤1051 ≤ m ≤ 10^5) indicating the number of vertices and edges in the original graph.

For the following mm lines, the ii-th line contains two integers u_iu\_i and v_iv\_i (1≤u_i,v_i≤n1 ≤ u\_i , v\_i ≤ n) indicating an edge connecting vertices u_iu\_i and v_iv\_i with length 2i2^i. There are no self loops nor multiple edges. Note that the graph is not necessarily connected.

It’s guaranteed that neither the sum of nn nor the sum of mm of all test cases will exceed 10610^6.

출력

For each test case output one line. If there are no simple cycles in the graph output “-1” (without quotes); Otherwise output kk integers separated by a space in increasing order indicating the indices of the edges in the simple cycle with the smallest length. It can be shown that there is at most one answer.

힌트

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 22, 44, 55 and 66 with a length of 22+24+25+26=1162^2 + 2^4 + 2^5 + 2^6 = 116.

예제1

  1. 예제 1

    입력
    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
    
    예상 출력
    2 4 5 6
    -1