rustworkx.connected_components#

connected_components(graph, /)#

在无向图中查找连通组件

一个连通分量是无向图的一个子集,其中子集中的任意两个顶点之间都存在路径,并且该子集不与图中的其他额外顶点相连。
>>> G = rx.PyGraph()
>>> G.extend_from_edge_list([(0, 1), (1, 2), (3, 4)])
>>> rx.connected_components(G)
[{0, 1, 2}, {3, 4}]

要获取仅这些组件的数量,请查阅 [number_connected_components]。

对于有向图,请参考 [weakly_connected_components] 和 [strongly_connected_components]。

Parameters:

graph (PyGraph) – 用于查询连通分量的无向图

Returns:

节点索引集合的列表,其中每个集合是图的一个连通分量

Return type:

列表[集合[整数]]