#P8435. 【模板】点双连通分量

【模板】点双连通分量

Problem Description

Given an undirected graph with nn nodes and mm edges, output the number of its vertex-biconnected components, and output each vertex-biconnected component.

Input Format

The first line contains two integers nn and mm.

The next mm lines each contain two integers u,vu, v, representing an undirected edge.

Output Format

The first line contains an integer xx, the number of vertex-biconnected components.

The next xx lines: the first number is aa, the number of nodes in this component, followed by aa numbers describing a vertex-biconnected component.

You may output the vertex-biconnected components in any order, and the nodes within each component in any order.

5 8
1 3
2 4
4 3
1 2
4 5
5 1
2 4
1 1
1
5 1 2 3 4 5
5 3
1 2
2 3
1 3
3
1 4
1 5
3 1 2 3
6 5
1 3
2 4
1 2
4 6
2 3
4
2 6 4
2 4 2
3 3 2 1
1 5
7 8
1 3
2 4
3 5
2 5
6 4
2 5
6 3
2 7
3
2 7 2
5 5 2 4 6 3
2 3 1
1 1
1 1
1
1 1

Hint

Explanation for Sample 4:

Nodes with the same color belong to the same component.

Friendly reminder: Please carefully consider isolated nodes and self-loops (Sample 5).


Constraints: For 100%100\% of the testdata, 1n5×1051 \le n \le 5 \times 10^5, 1m2×1061 \le m \le 2 \times 10^6.

subtask nn mm Score
11 1n1001 \le n \le 100 1m5001 \le m \le 500 2525
22 1n50001 \le n \le 5000 1m5×1041 \le m \le 5 \times 10^4
33 1n2×1051 \le n \le 2\times 10^5 1m5×1051 \le m \le 5\times 10^5
44 1n5×1051 \le n \le 5 \times10 ^5 1m2×1061 \le m \le 2 \times 10^6

This problem is not strict on constant factors. Both the time limit and memory limit are set large, so any correct solution can pass.


Data Updates

  • 2022/7/142022/7/14 Strengthened the testdata.
  • 2022/11/262022/11/26 Added 1010 groups of smaller testdata (1n,m101 \le n, m \le 10) for easier debugging.
  • 2022/12/312022/12/31 Reorganized the subtasksubtask setup and added several groups of extreme testdata.
  • 2023/1/12023/1/1 Found an issue in the testdata added yesterday, and it has been fixed.
  • 2025/10/292025/10/29 Added an extra hack test.

Surprise: After getting AC, remember to place your mouse over the test points to see the feedback information. There is a surprise.

Translated by ChatGPT 5