QOJ.ac

QOJ

実行時間制限: 1 s メモリ制限: 512 MB 満点: 100

#3846. Link-Cut Tree

統計

BaoBao 刚刚学会了如何使用一种名为 Link-Cut Tree 的数据结构来寻找图中的环,并决定尝试一下。BaoBao 得到一个包含 $n$ 个顶点和 $m$ 条边的无向图,其中第 $i$ 条边的长度等于 $2^i$。她需要找到一个长度最小的简单环。

简单环是原图的一个子图,包含 $k$ ($3 \le k \le n$) 个顶点 $a_1, a_2, \dots, a_k$ 和 $k$ 条边,使得对于所有 $1 \le i \le k$,子图中都存在一条连接顶点 $a_i$ 和 $a_{(i \mod k)+1}$ 的边。简单环的长度是环中所有边的长度之和。

输入格式

输入包含多组测试数据。第一行包含一个整数 $T$,表示测试数据的组数。对于每组测试数据:

第一行包含两个整数 $n$ 和 $m$ ($3 \le n \le 10^5, 1 \le m \le 10^5$),分别表示原图的顶点数和边数。

接下来的 $m$ 行中,第 $i$ 行包含两个整数 $u_i$ 和 $v_i$ ($1 \le u_i, v_i \le n$),表示一条连接顶点 $u_i$ 和 $v_i$ 的边,其长度为 $2^i$。图中不存在自环或重边。注意,图不一定是连通的。

保证所有测试数据的 $n$ 之和与 $m$ 之和均不超过 $10^6$。

输出格式

对于每组测试数据,输出一行。如果图中不存在简单环,输出 “-1”(不含引号);否则,输出 $k$ 个整数,按升序排列,表示构成长度最小的简单环的边的编号。可以证明答案至多只有一个。

请不要在每行末尾输出多余的空格,否则你的解可能被判定为错误!

样例

样例输入 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

样例输出 1

2 4 5 6
-1

说明

第一个样例测试数据如下图所示。边旁边的整数分别是它们的编号(括号外)和长度(括号内)。长度最小的简单环由编号为 2, 4, 5 和 6 的边组成,长度为 $2^2 + 2^4 + 2^5 + 2^6 = 120$。

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.