
    ިsg	                     J    d dl mZ d dlZdgZej
                  dd       Zd Zy)    )defaultdictNk_clique_communitiesc              #   l  K   |dk  rt        j                  d| d      |t        j                  |       }|D cg c]  }t        |      |k\  st	        |       }}t        t              }|D ]  }|D ]  }||   j                  |         t        j                         }|j                  |       |D ]F  }t        ||      D ]5  }t        |j                  |            |dz
  k\  s$|j                  ||       7 H t        j                  |      D ]  }	t	        j                  |	   yc c}w w)u8  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
    --------
    >>> G = nx.complete_graph(5)
    >>> K5 = nx.convert_node_labels_to_integers(G, first_label=2)
    >>> G.add_edges_from(K5.edges())
    >>> c = list(nx.community.k_clique_communities(G, 4))
    >>> sorted(list(c[0]))
    [0, 1, 2, 3, 4, 5, 6]
    >>> list(nx.community.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.N   )nxNetworkXErrorfind_cliqueslen	frozensetr   listappendGraphadd_nodes_from_get_adjacent_cliquesintersectionadd_edgeconnected_componentsunion)
Gkcliquescmembership_dictcliquenode
perc_graph
adj_clique	components
             X/var/www/html/venv/lib/python3.12/site-packages/networkx/algorithms/community/kclique.pyr   r      s8    N 	1uA3&ABCC//!$%,<A!y|<G< "$'O 1 	1DD!((0	11
 Jg& 8/H 	8J6&&z23A>##FJ7	88 ,,Z8 ,		*+,% =s   :D4D/D/BD4*A
D4c                 j    t               }| D ]#  }||   D ]  }| |k7  s	|j                  |        % |S N)setadd)r   r   adjacent_cliquesnr   s        r    r   r   I   sK    u 1)!, 	1J# $$Z0	11     r"   )collectionsr   networkxr   __all___dispatchabler   r    r'   r    <module>r-      s3    # !
" =, =,@r'   