#P15869. 【MX-X26-T5】「Cfz Round 7」anybody can finds love (expect you)

    ID: 17919 远端评测题 1500ms 512MiB 尝试: 0 已通过: 0 显示难度省选/NOI− 上传者: 标签>Special JudgeO2优化梦熊比赛

【MX-X26-T5】「Cfz Round 7」anybody can finds love (expect you)

Problem Description

You are given a connected undirected graph G=(V,E)G=(V,E) with nn vertices and mm edges, where multiple edges may exist.

An edge sequence e1,…,eme_1,\dots,e_m is called "鱼鱼" if and only if:

  1. The multiset {ei}\{e_i\} is the same as the edge set EE;
  2. For all 1≤i<m1 \le i \lt m, the ending vertex of eie_i is the same as the starting vertex of ei+1e_{i+1};
  3. For all 1≤i≤m1 \le i \le m, the starting vertex of eie_i is different from the ending vertex of e(i mod m)+1e_{(i \bmod m)+1};
  4. The starting vertex of e1e_1 is the same as the ending vertex of eme_m.

That is, the sequence ee forms an Eulerian circuit, and there is no pattern of the form x→y→xx \to y \to x in the circuit.

You need to construct a "鱼鱼" sequence, or report that no such sequence exists.

For convenience, when a "鱼鱼" sequence exists, you only need to output the vertices visited in order along the circuit.

Input Format

This problem has multiple test cases.

The first line contains two integers c,tc,t, representing the subtask index of this test and the number of test cases. The sample satisfies c=0c=0.

Then the test cases follow. For each test case:

  • The first line contains two integers n,mn,m.
  • The next mm lines each contain two integers xi,yix_i,y_i, indicating that there is an edge connecting vertex xix_i and vertex yiy_i in the graph.

Output Format

For each test case:

  • If there is no solution, output one line containing a single integer −1-1.
  • Otherwise, output one line containing m+1m+1 integers, representing the vertices visited in order along the circuit.
0 2
4 6
1 2
3 1
2 3
2 4
3 4
3 2
2 2
1 2
1 2
2 3 1 2 3 4 2
-1

Hint

Sample 1 Explanation

For the 11st test case, {(1,2),(2,3),(3,4),(4,2),(2,3),(3,1)}\{(1,2),(2,3),(3,4),(4,2),(2,3),(3,1)\} is also a valid "鱼鱼" sequence, but {(2,4),(4,3),(3,2),(2,3),(3,1),(1,2)}\{(2,4),(4,3),(3,2),(2,3),(3,1),(1,2)\} is not a valid "鱼鱼" sequence.

For the 22nd test case, it is easy to prove that no "鱼鱼" sequence exists.

Constraints

For all testdata:

  • 1≤t≤1051\le t\le 10^5;
  • 1≤n,m≤1061\le n,m\le 10^6, ∑n≤106\sum n\le 10^6, ∑m≤106\sum m \le 10^6;
  • For all 1≤i≤m1 \le i \le m, 1≤xi,yi≤n1\le x_i,y_i\le n, xi≠yix_i\neq y_i;
  • The given undirected graph is connected.

This problem uses bundled tests.

  • Subtask 1 (15 points): ∑m≤10\sum m\le 10;
  • Subtask 2 (18 points): ∑m≤20\sum m\le 20;
  • Subtask 3 (15 points): For all 1≤u<v≤n1 \le u \lt v \le n, there is at most 11 edge connecting vertices uu and vv.
  • Subtask 4 (24 ponits): For all 1≤u<v≤n1 \le u \lt v \le n, there are at most 22 edges connecting vertices uu and vv.
  • Subtask 5 (28 points): No special constraints.

Translated by ChatGPT 5