#P15439. [蓝桥杯 2025 国 Python B] 连通块
[蓝桥杯 2025 国 Python B] 连通块
Problem Description
Given an undirected complete graph with nodes, delete edges from it. Find how many connected components the graph has.
Output the number of connected components, and output the details of each connected component.
Input Format
The first line of input contains two positive integers , separated by a space, representing the number of nodes and the number of deleted edges.
The next lines each contain two positive integers , separated by a space, indicating that the edge between and is deleted. It is guaranteed that the same edge will not be deleted twice.
Output Format
The first line of output contains an integer , representing the number of connected components.
The next lines each describe one connected component. The first number indicates the number of nodes in this connected component, followed by numbers giving the node indices in order, with a space between adjacent integers. Output the connected components in increasing order of their smallest node; within each connected component, output the nodes in increasing order.
5 6
1 2
2 4
2 5
1 3
3 4
3 5
2
3 1 4 5
2 2 3
Hint
Constraints and Conventions for Test Cases
For of the test cases, .
For all test cases, , , and .
Translated by ChatGPT 5