奇数环AI (CI翻译)
Problem Statement
题目描述
AI (CI翻译)You are given a simple connected undirected graph with $N$ vertices numbered $1$ through $N$ and $M$ edges. The $i$-th edge connects vertices $a_i$ and $b_i$.
给定一张简单连通无向图,包含 $N$ 个顶点,编号为 $1$ 到 $N$,以及 $M$ 条边。第 $i$ 条边连接顶点 $a_i$ 和 $b_i$。AI (CI翻译)
Determine whether there exists a cycle consisting of an odd number of vertices, and if one exists, find one such cycle.
请判断图中是否存在一个由奇数个顶点组成的环;如果存在,请找出其中一个。AI (CI翻译)
Formally, determine whether there exists an integer sequence $(v_1,v_2,\ldots,v_K)$ satisfying all of the following conditions, and if one exists, find one such sequence.
形式化地,请判断是否存在一个整数序列 $(v_1,v_2,\ldots,v_K)$ 满足以下所有条件;如果存在,请找出这样一个序列。AI (CI翻译)
$K$is an odd number at least$3$.$v_1,v_2,\ldots,v_K$are all distinct.- For every integer
$i$with$1\le i \le K$, there is an edge between vertices$v_i$and$v_{i+1}$, where$v_{K+1} = v_1$.
$K$是一个不小于$3$的奇数。$v_1,v_2,\ldots,v_K$两两不同。- 对于每个满足
$1\le i \le K$的整数$i$,顶点$v_i$和$v_{i+1}$之间都有一条边,其中$v_{K+1} = v_1$。
You are given $T$ test cases; solve each of them.
给定 $T$ 组测试用例,请分别求解。AI (CI翻译)
Constraints
约束条件
AI (CI翻译)$1 \le T \le 2\times10^5$$1 \le N, M \le 2\times10^5$- The sum of
$N$over all test cases is at most$2\times10^5$. - The sum of
$M$over all test cases is at most$2\times10^5$. $1 \le a_i,b_i \le N$$a_i\ne b_i$- The given graph is a simple connected undirected graph.
- All input values are integers.
$1 \le T \le 2\times10^5$$1 \le N, M \le 2\times10^5$- 所有测试用例的
$N$之和不超过$2\times10^5$。 - 所有测试用例的
$M$之和不超过$2\times10^5$。 $1 \le a_i,b_i \le N$$a_i\ne b_i$- 给定的图是一张简单连通无向图。
- 输入的所有数值均为整数。
Input
输入格式
AI (CI翻译)The input is given from Standard Input in the following format:
输入从标准输入读入,格式如下:AI (CI翻译)
T
\mathrm{case}_1
\mathrm{case}_2
\vdots
\mathrm{case}_T
T
\mathrm{case}_1
\mathrm{case}_2
\vdots
\mathrm{case}_TAI (CI翻译)
Each test case is given in the following format:
每组测试用例的格式如下:AI (CI翻译)
N M
a_1 b_1
a_2 b_2
\vdots
a_M b_M
N M
a_1 b_1
a_2 b_2
\vdots
a_M b_MAI (CI翻译)
Output
输出格式
AI (CI翻译)For each test case, if there is no sequence satisfying the conditions, output -1. If one exists, output one such sequence in the following format:
对于每组测试用例,如果不存在满足条件的序列,输出 -1。如果存在,则按以下格式输出其中一个这样的序列:AI (CI翻译)
K
v_1 v_2 \ldots v_K
K
v_1 v_2 \ldots v_KAI (CI翻译)
If multiple sequences satisfy the conditions, any of them will be accepted.
如果有多个序列满足条件,输出任意一个均可通过。AI (CI翻译)
样例
4
3 3
1 2
2 3
1 3
7 7
1 2
2 3
3 4
1 4
4 5
5 6
6 7
5 5
1 2
2 3
3 4
4 5
1 5
9 10
1 2
2 3
3 4
4 5
1 5
6 7
7 8
8 9
6 9
1 6
3
2 1 3
-1
5
3 2 1 5 4
5
3 2 1 5 4
题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(gpt-6.1-sol),如有出入请以原文为准。