#ABC472E. 奇环 / Odd Cycle

奇环 / Odd Cycle

Problem Statement

You are given a simple connected undirected graph with NN vertices numbered 11 through NN and MM edges. The ii-th edge connects vertices aia_i and bib_i.

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 (v1,v2,,vK)(v_1,v_2,\ldots,v_K) satisfying all of the following conditions, and if one exists, find one such sequence.

  • KK is an odd number at least 33.
  • v1,v2,,vKv_1,v_2,\ldots,v_K are all distinct.
  • For every integer ii with 1iK1\le i \le K, there is an edge between vertices viv_i and vi+1v_{i+1}, where vK+1=v1v_{K+1} = v_1.

You are given TT test cases; solve each of them.

Constraints

  • 1T2×1051 \le T \le 2\times10^5
  • 1N,M2×1051 \le N, M \le 2\times10^5
  • The sum of NN over all test cases is at most 2×1052\times10^5.
  • The sum of MM over all test cases is at most 2×1052\times10^5.
  • 1ai,biN1 \le a_i, b_i \le N
  • aibia_i\ne b_i
  • 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:

  • TT
  • case1\mathrm{case}_1
  • case2\mathrm{case}_2
  • \vdots
  • caseT\mathrm{case}_T

Each test case is given in the following format:

  • NN MM
  • a1a_1 b1b_1
  • a2a_2 b2b_2
  • \vdots
  • aMa_M bMb_M

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:

  • KK
  • v1v_1 v2v_2 \ldots vKv_K

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 (2,1,3)(2,1,3) satisfies the conditions: the edges (2,1),(1,3),(3,2)(2, 1), (1, 3), (3, 2) all exist. Outputs such as v=(2,3,1)v = (2, 3, 1) are also accepted.

In the second test case, there is no cycle with an odd number of vertices, so no sequence satisfies the conditions.