#P16967. [SCCPC 2026] 环基基环树
[SCCPC 2026] 环基基环树
Problem Description
There is an undirected connected simple graph , which is a unicyclic tree. That is, if has vertices, then it also has exactly edges.
Now the graph undergoes the following mutation:
For each original vertex , choose an integer , and replace vertex with a simple cycle of length . For each original edge , choose any vertex on the cycle and any vertex on the cycle , and add an edge between these two chosen vertices.
Different original edges may connect to the same vertex on the same cycle, or to different vertices. It is guaranteed that the resulting graph after mutation is still an undirected connected simple graph.
Now you are given the mutated graph. You need to restore any unicyclic tree that is isomorphic to the original graph .
If there are multiple answers, output any one of them.
Input Format
The first line contains a positive integer (), denoting the number of test cases.
For each test case:
The first line contains two integers (), denoting the number of vertices and edges in the mutated graph.
The next lines each contain two integers (), denoting an undirected edge in the mutated graph.
It is guaranteed that the input graph is an undirected connected simple graph, and it can definitely be obtained by mutating some unicyclic tree according to the rules in the statement.
It is guaranteed that across all test cases, and .
Output Format
For each test case:
The first line outputs an integer , denoting the number of vertices in the unicyclic tree you restored.
Then output lines, each containing two integers , denoting an undirected edge in the unicyclic tree you restored.
Your output graph only needs to be isomorphic to some valid original graph. The vertex labels and the order of edges can be arbitrary.
2
9 12
1 2
2 3
3 1
4 5
5 6
6 4
7 8
8 9
9 7
1 4
2 7
5 8
12 16
1 2
2 3
3 1
4 5
5 6
6 4
7 8
8 9
9 7
10 11
11 12
12 10
1 4
5 7
8 2
6 10
3
1 2
1 3
2 3
4
1 3
2 3
2 4
3 4
Hint
Translated by ChatGPT 5