def aggregate_clusters(G):
    """ Takes as input the labeled graph and outputs a dictionary with the keys
    being cluster IDs and the values being sets of cluster elements. """
    clusters = {}
    for node in G:
        label = G.nodes[node]['label']
        if label not in clusters:
            clusters[label] = {node}
        else:
            clusters[label].add(node)
    return clusters
