#P15869. 【MX-X26-T5】「Cfz Round 7」anybody can finds love (expect you)
【MX-X26-T5】「Cfz Round 7」anybody can finds love (expect you)
Problem Description
You are given a connected undirected graph with vertices and edges, where multiple edges may exist.
An edge sequence is called "鱼鱼" if and only if:
- The multiset is the same as the edge set ;
- For all , the ending vertex of is the same as the starting vertex of ;
- For all , the starting vertex of is different from the ending vertex of ;
- The starting vertex of is the same as the ending vertex of .
That is, the sequence forms an Eulerian circuit, and there is no pattern of the form 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 , representing the subtask index of this test and the number of test cases. The sample satisfies .
Then the test cases follow. For each test case:
- The first line contains two integers .
- The next lines each contain two integers , indicating that there is an edge connecting vertex and vertex in the graph.
Output Format
For each test case:
- If there is no solution, output one line containing a single integer .
- Otherwise, output one line containing 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 st test case, is also a valid "鱼鱼" sequence, but is not a valid "鱼鱼" sequence.
For the nd test case, it is easy to prove that no "鱼鱼" sequence exists.
Constraints
For all testdata:
- ;
- , , ;
- For all , , ;
- The given undirected graph is connected.
This problem uses bundled tests.
- Subtask 1 (15 points): ;
- Subtask 2 (18 points): ;
- Subtask 3 (15 points): For all , there is at most edge connecting vertices and .
- Subtask 4 (24 ponits): For all , there are at most edges connecting vertices and .
- Subtask 5 (28 points): No special constraints.
Translated by ChatGPT 5