§
    bŠtjà  ã                   ó@  — d Z ddlZddlmZ ddlmZ g d¢Z ed¦  «        ej        d„ ¦   «         ¦   «         Z	 ed¦  «        ej        d	„ ¦   «         ¦   «         Z
 ed¦  «        ej        d
„ ¦   «         ¦   «         Z ed¦  «        ej        d„ ¦   «         ¦   «         Zd„ ZdS )zConnected components.é    N)Únot_implemented_foré   )Úarbitrary_element)Únumber_connected_componentsÚconnected_componentsÚis_connectedÚnode_connected_componentÚdirectedc              #   óÊ   K  — t          ¦   «         }t          | ¦  «        }| D ]@}||vr:t          | |t          |¦  «        z
  |¦  «        }|                     |¦  «         |V — ŒAdS )aÔ  Generate connected components.

    The connected components of an undirected graph partition the graph into
    disjoint sets of nodes. Each of these sets induces a subgraph of graph
    `G` that is connected and not part of any larger connected subgraph.

    A graph is connected (:func:`is_connected`) if, for every pair of distinct
    nodes, there is a path between them. If there is a pair of nodes for
    which such path does not exist, the graph is not connected (also referred
    to as "disconnected").

    A graph consisting of a single node and no edges is connected.
    Connectivity is undefined for the null graph (graph with no nodes).

    Parameters
    ----------
    G : NetworkX graph
       An undirected graph

    Yields
    ------
    comp : set
       A set of nodes in one connected component of the graph.

    Raises
    ------
    NetworkXNotImplemented
        If G is directed.

    Examples
    --------
    Generate a sorted list of connected components, largest first.

    >>> G = nx.path_graph(4)
    >>> nx.add_path(G, [10, 11, 12])
    >>> [len(c) for c in sorted(nx.connected_components(G), key=len, reverse=True)]
    [4, 3]

    If you only want the largest connected component, it's more
    efficient to use max instead of sort.

    >>> largest_cc = max(nx.connected_components(G), key=len)

    To create the induced subgraph of each component use:

    >>> S = [G.subgraph(c).copy() for c in nx.connected_components(G)]

    See Also
    --------
    number_connected_components
    is_connected
    number_weakly_connected_components
    number_strongly_connected_components

    Notes
    -----
    This function is for undirected graphs only. For directed graphs, use
    :func:`strongly_connected_components` or
    :func:`weakly_connected_components`.

    The algorithm is based on a Breadth-First Search (BFS) traversal and its
    time complexity is $O(n + m)$, where $n$ is the number of nodes and $m$ the
    number of edges in the graph.

    N)ÚsetÚlenÚ
_plain_bfsÚupdate)ÚGÚseenÚnÚvÚcs        úf/var/www/html/CA-Chatbot/venv/lib/python3.11/site-packages/networkx/algorithms/components/connected.pyr   r      ss   è è € õH ‰5Œ5€DÝˆA‰Œ€AØð ð ˆØ�Dˆ=ˆ=Ý˜1˜a¥# d¡)¤)™m¨QÑ/Ô/ˆAØ�KŠK˜‰NŒNˆNØˆGˆGˆGøð	ð ó    c                 óN   — t          d„ t          | ¦  «        D ¦   «         ¦  «        S )a(  Returns the number of connected components.

    The connected components of an undirected graph partition the graph into
    disjoint sets of nodes. Each of these sets induces a subgraph of graph
    `G` that is connected and not part of any larger connected subgraph.

    A graph is connected (:func:`is_connected`) if, for every pair of distinct
    nodes, there is a path between them. If there is a pair of nodes for
    which such path does not exist, the graph is not connected (also referred
    to as "disconnected").

    A graph consisting of a single node and no edges is connected.
    Connectivity is undefined for the null graph (graph with no nodes).

    Parameters
    ----------
    G : NetworkX graph
       An undirected graph.

    Returns
    -------
    n : integer
       Number of connected components

    Raises
    ------
    NetworkXNotImplemented
        If G is directed.

    Examples
    --------
    >>> G = nx.Graph([(0, 1), (1, 2), (5, 6), (3, 4)])
    >>> nx.number_connected_components(G)
    3

    See Also
    --------
    connected_components
    is_connected
    number_weakly_connected_components
    number_strongly_connected_components

    Notes
    -----
    This function is for undirected graphs only. For directed graphs, use
    :func:`number_strongly_connected_components` or
    :func:`number_weakly_connected_components`.

    The algorithm is based on a Breadth-First Search (BFS) traversal and its
    time complexity is $O(n + m)$, where $n$ is the number of nodes and $m$ the
    number of edges in the graph.

    c              3   ó   K  — | ]}d V — ŒdS )é   N© )Ú.0Ú_s     r   ú	<genexpr>z.number_connected_components.<locals>.<genexpr>•   s"   è è € Ð2Ð2�QˆqÐ2Ð2Ð2Ð2Ð2Ð2r   )Úsumr   )r   s    r   r   r   ]   s+   € õp Ð2Ð2Õ.¨qÑ1Ô1Ð2Ñ2Ô2Ñ2Ô2Ð2r   c                 ó®   — t          | ¦  «        }|dk    rt          j        d¦  «        ‚t          t          t	          | ¦  «        ¦  «        ¦  «        |k    S )a  Returns True if the graph is connected, False otherwise.

    A graph is connected if, for every pair of distinct nodes, there is a
    path between them. If there is a pair of nodes for which such path does
    not exist, the graph is not connected (also referred to as "disconnected").

    A graph consisting of a single node and no edges is connected.
    Connectivity is undefined for the null graph (graph with no nodes).

    Parameters
    ----------
    G : NetworkX Graph
       An undirected graph.

    Returns
    -------
    connected : bool
      True if the graph is connected, False otherwise.

    Raises
    ------
    NetworkXNotImplemented
        If G is directed.

    Examples
    --------
    >>> G = nx.path_graph(4)
    >>> print(nx.is_connected(G))
    True

    See Also
    --------
    is_strongly_connected
    is_weakly_connected
    is_semiconnected
    is_biconnected
    connected_components

    Notes
    -----
    This function is for undirected graphs only. For directed graphs, use
    :func:`is_strongly_connected` or :func:`is_weakly_connected`.

    The algorithm is based on a Breadth-First Search (BFS) traversal and its
    time complexity is $O(n + m)$, where $n$ is the number of nodes and $m$ the
    number of edges in the graph.

    r   z-Connectivity is undefined for the null graph.)r   ÚnxÚNetworkXPointlessConceptÚnextr   ©r   r   s     r   r   r   ˜   sW   € õf 	ˆA‰Œ€AØˆA‚v€vÝÔ)Ø;ñ
ô 
ð 	
õ �tÕ(¨Ñ+Ô+Ñ,Ô,Ñ-Ô-°Ò2Ð2r   c                 ó>   — t          | t          | ¦  «        |¦  «        S )a‹  Returns the set of nodes in the component of graph containing node n.

    A connected component is a set of nodes that induces a subgraph of graph
    `G` that is connected and not part of any larger connected subgraph.

    A graph is connected (:func:`is_connected`) if, for every pair of distinct
    nodes, there is a path between them. If there is a pair of nodes for
    which such path does not exist, the graph is not connected (also referred
    to as "disconnected").

    A graph consisting of a single node and no edges is connected.
    Connectivity is undefined for the null graph (graph with no nodes).

    Parameters
    ----------
    G : NetworkX Graph
       An undirected graph.

    n : node label
       A node in G

    Returns
    -------
    comp : set
       A set of nodes in the component of G containing node n.

    Raises
    ------
    NetworkXNotImplemented
        If G is directed.

    Examples
    --------
    >>> G = nx.Graph([(0, 1), (1, 2), (5, 6), (3, 4)])
    >>> nx.node_connected_component(G, 0)  # nodes of component that contains node 0
    {0, 1, 2}

    See Also
    --------
    connected_components

    Notes
    -----
    This function is for undirected graphs only.

    The algorithm is based on a Breadth-First Search (BFS) traversal and its
    time complexity is $O(n + m)$, where $n$ is the number of nodes and $m$ the
    number of edges in the graph.

    )r   r   r#   s     r   r	   r	   Ó   s   € õj �a�˜Q™œ Ñ#Ô#Ð#r   c                 óÚ   — | j         }|h}|g}|r[|}g }|D ]R}||         D ]0}||vr*|                     |¦  «         |                     |¦  «         Œ1t          |¦  «        |k    r|c S ŒS|°[|S )zA fast BFS node generator)Ú_adjÚaddÚappendr   )	r   r   ÚsourceÚadjr   Ú	nextlevelÚ	thislevelr   Úws	            r   r   r     s¦   € à
Œ&€CØˆ8€DØ�€IØ
ð 	Øˆ	Øˆ	Øð 	ð 	ˆAØ˜”Vð (ð (�Ø˜D�=�=Ø—H’H˜Q‘K”K�KØ×$Ò$ QÑ'Ô'Ð'øÝ�4‰yŒy˜AŠ~ˆ~Ø���ð ð ð 	ð €Kr   )Ú__doc__Únetworkxr    Únetworkx.utils.decoratorsr   Úutilsr   Ú__all__Ú_dispatchabler   r   r   r	   r   r   r   r   ú<module>r4      s@  ðØ Ð à Ð Ð Ð Ø 9Ð 9Ð 9Ð 9Ð 9Ð 9à &Ð &Ð &Ð &Ð &Ð &ðð ð €ð Ð�ZÑ Ô ØÔðHð Hñ Ôñ !Ô ðHðV Ð�ZÑ Ô ØÔð63ð 63ñ Ôñ !Ô ð63ðr Ð�ZÑ Ô ØÔð63ð 63ñ Ôñ !Ô ð63ðr Ð�ZÑ Ô ØÔð3$ð 3$ñ Ôñ !Ô ð3$ðlð ð ð ð r   