#P16967. [SCCPC 2026] 环基基环树

    ID: 19051 远端评测题 2000ms 1024MiB 尝试: 0 已通过: 0 显示难度省选/NOI− 上传者: 标签>图论四川Special Judge双连通分量2026省赛/邀请赛

[SCCPC 2026] 环基基环树

Problem Description

There is an undirected connected simple graph GG, which is a unicyclic tree. That is, if GG has kk vertices, then it also has exactly kk edges.

Now the graph undergoes the following mutation:

For each original vertex xx, choose an integer cx3c_x \ge 3, and replace vertex xx with a simple cycle CxC_x of length cxc_x. For each original edge (u,v)(u,v), choose any vertex on the cycle CuC_u and any vertex on the cycle CvC_v, 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 GG.

If there are multiple answers, output any one of them.

Input Format

The first line contains a positive integer tt (1t1051 \le t \le 10^5), denoting the number of test cases.

For each test case:

The first line contains two integers n,mn, m (9n106, 12m1069 \le n \le 10^6,\ 12 \le m \le 10^6), denoting the number of vertices and edges in the mutated graph.

The next mm lines each contain two integers u,vu, v (1u,vn, uv1 \le u, v \le n,\ u \ne v), 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, n106\sum n \le 10^6 and m1333333\sum m \le 1333333.

Output Format

For each test case:

The first line outputs an integer kk, denoting the number of vertices in the unicyclic tree you restored.

Then output kk lines, each containing two integers u,vu, v, 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