#P16921. [JLCPC 2026] 拆分树
[JLCPC 2026] 拆分树
Problem Description
is playing a game of merging two trees into one graph. He took two trees with vertices each and merged them into an undirected unweighted graph with vertices and edges. However, he found that he cannot restore this graph back into two trees. Please help him.
Formally, you need to partition all edges into two sets and , such that both and form a spanning tree of .
You may output any valid solution. It is guaranteed that a valid solution always exists.
Note: The graph may contain multiple edges, but it is guaranteed to have no self-loops.
Input Format
The first line contains an integer (), the number of test cases. Then follow test cases, each described as follows.
- The first line contains an integer (), the number of vertices.
- The next lines each contain two integers (, ), describing an edge. Edges are numbered from to in the input order.
It is guaranteed that does not exceed .
Output Format
For each test case, output integers (in increasing order), indicating the edge indices included in the first spanning tree. The remaining edges should also form a spanning tree.
2
3
1 2
2 3
1 3
1 2
4
1 2
2 3
3 4
1 4
1 3
2 4
1 2
1 2 3
Hint
For the first sample, edges correspond to and form a spanning tree. The remaining edges correspond to and also form a spanning tree.
For the second sample, edges correspond to and form a spanning tree. The remaining edges correspond to and also form a spanning tree.
Translated by ChatGPT 5