You are viewing a single comment's thread. Return to all comments →
Python
def componentsInGraph(gb): clusters = [] for a, b in gb: clusters_to_fuse = [] for cluster in clusters: if a in cluster or b in cluster: clusters_to_fuse.append(cluster) if clusters_to_fuse: fused_cluster = {a, b} for cluster in clusters_to_fuse: for node in cluster: fused_cluster.add(node) clusters.remove(cluster) clusters.append(fused_cluster) else: clusters.append({a, b}) clusters_len = list(map(len, clusters)) return [min(clusters_len), max(clusters_len)]
Seems like cookies are disabled on this browser, please enable them to open this website
Components in a graph
You are viewing a single comment's thread. Return to all comments →
Python