#ABC472E. 奇环 / Odd Cycle
奇环 / Odd Cycle
Problem Statement
You are given a simple connected undirected graph with vertices numbered through and edges. The -th edge connects vertices and .
Determine whether there exists a cycle consisting of an odd number of vertices, and if one exists, find one such cycle.
Formally, determine whether there exists an integer sequence satisfying all of the following conditions, and if one exists, find one such sequence.
- is an odd number at least .
- are all distinct.
- For every integer with , there is an edge between vertices and , where .
You are given test cases; solve each of them.
Constraints
- The sum of over all test cases is at most .
- The sum of over all test cases is at most .
- The given graph is a simple connected undirected graph.
- All input values are integers.
Input
The input is given from Standard Input in the following format:
Each test case is given in the following format:
Output
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:
If multiple sequences satisfy the conditions, any of them will be accepted.
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
In the first test case, the sequence satisfies the conditions: the edges all exist. Outputs such as are also accepted.
In the second test case, there is no cycle with an odd number of vertices, so no sequence satisfies the conditions.
- Source: AtCoder ABC 472 E
相关
在下列比赛中: