o
    ˷e	                     @   s0   d dl mZ d dlZdgZdddZdd ZdS )    )defaultdictNk_clique_communitiesc           	      #   s     dk rt d  d|du rt | } fdd|D }tt}|D ]}|D ]	}|| | q*q&t  }|| |D ]}t||D ]}t	|
| d krZ||| qGq@t |D ]}tj| V  qadS )ue  Find k-clique communities in graph using the percolation method.

    A k-clique community is the union of all cliques of size k that
    can be reached through adjacent (sharing k-1 nodes) k-cliques.

    Parameters
    ----------
    G : NetworkX graph

    k : int
       Size of smallest clique

    cliques: list or generator
       Precomputed cliques (use networkx.find_cliques(G))

    Returns
    -------
    Yields sets of nodes, one for each k-clique community.

    Examples
    --------
    >>> from networkx.algorithms.community import k_clique_communities
    >>> G = nx.complete_graph(5)
    >>> K5 = nx.convert_node_labels_to_integers(G, first_label=2)
    >>> G.add_edges_from(K5.edges())
    >>> c = list(k_clique_communities(G, 4))
    >>> sorted(list(c[0]))
    [0, 1, 2, 3, 4, 5, 6]
    >>> list(k_clique_communities(G, 6))
    []

    References
    ----------
    .. [1] Gergely Palla, Imre Derényi, Illés Farkas1, and Tamás Vicsek,
       Uncovering the overlapping community structure of complex networks
       in nature and society Nature 435, 814-818, 2005,
       doi:10.1038/nature03607
       zk=z, k must be greater than 1.Nc                    s    g | ]}t | krt|qS  )len	frozenset).0ckr   \/var/www/ideatree/venv/lib/python3.10/site-packages/networkx/algorithms/community/kclique.py
<listcomp>3   s     z(k_clique_communities.<locals>.<listcomp>   )nxNetworkXErrorfind_cliquesr   listappendGraphadd_nodes_from_get_adjacent_cliquesr   intersectionadd_edgeconnected_componentsr   union)	Gr   cliquesmembership_dictcliquenode
perc_graph
adj_clique	componentr   r
   r   r      s,   '

c                 C   s4   t  }| D ]}|| D ]}| |kr|| qq|S N)setadd)r   r   adjacent_cliquesnr!   r   r   r   r   I   s   
r   r#   )collectionsr   networkxr   __all__r   r   r   r   r   r   <module>   s
    
A