这些是图形的 连接组件
,可以使用诸如的图形库找到
networkx。对于第二个示例:
>>> edges = [(1, 5), (4, 2), (4, 3), (5, 4), (6, 3), (7, 6), (8, 9)]>>> graph = nx.Graph(edges) >>> [tuple(c) for c in nx.connected_components(graph)][(1, 2, 3, 4, 5, 6, 7), (8, 9)]

这些是图形的 连接组件
,可以使用诸如的图形库找到
networkx。对于第二个示例:
>>> edges = [(1, 5), (4, 2), (4, 3), (5, 4), (6, 3), (7, 6), (8, 9)]>>> graph = nx.Graph(edges) >>> [tuple(c) for c in nx.connected_components(graph)][(1, 2, 3, 4, 5, 6, 7), (8, 9)]