Ë
    ©Ó^j·&  ã                   óX  — d Z ddlZddlmZ g d¢Z ed«      ej                  d„ «       «       Z ed«      ej                  dd„«       «       Z ed«      ej                  d„ «       «       Z	 ed«      ej                  d	„ «       «       Z
 ed«       ej                  d
¬«      dd„«       «       Zy)zStrongly connected components.é    N)Únot_implemented_for)Ú$number_strongly_connected_componentsÚstrongly_connected_componentsÚis_strongly_connectedÚ&kosaraju_strongly_connected_componentsÚcondensationÚ
undirectedc              #   óê  K  — i }i }t        «       }g }d}| D �ci c]  }|t        | j                  |   «      “Œ }}| D �],  }||vsŒ	|g}	|	sŒ|	d   }||vr
|dz   }|||<   d}
||   D ]  }||vsŒ|	j                  |«       d}
 n |
rà||   ||<   | j                  |   D ]?  }||vsŒ||   ||   kD  rt	        ||   ||   g«      ||<   Œ*t	        ||   ||   g«      ||<   ŒA |	j                  «        ||   ||   k(  r[|h}|r@||d      ||   kD  r2|j                  «       }|j                  |«       |r||d      ||   kD  rŒ2|j                  |«       |–— n|j                  |«       |	r�Œ�Œ/ yc c}w ­w)a³  Generate nodes in strongly connected components of graph.

    Parameters
    ----------
    G : NetworkX Graph
        A directed graph.

    Returns
    -------
    comp : generator of sets
        A generator of sets of nodes, one for each strongly connected
        component of G.

    Raises
    ------
    NetworkXNotImplemented
        If G is undirected.

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

    >>> G = nx.cycle_graph(4, create_using=nx.DiGraph())
    >>> nx.add_cycle(G, [10, 11, 12])
    >>> [
    ...     len(c)
    ...     for c in sorted(nx.strongly_connected_components(G), key=len, reverse=True)
    ... ]
    [4, 3]

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

    >>> largest = max(nx.strongly_connected_components(G), key=len)

    See Also
    --------
    connected_components
    weakly_connected_components
    kosaraju_strongly_connected_components

    Notes
    -----
    Uses Tarjan's algorithm[1]_ with Nuutila's modifications[2]_.
    Nonrecursive version of algorithm.

    References
    ----------
    .. [1] Depth-first search and linear graph algorithms, R. Tarjan
       SIAM Journal of Computing 1(2):146-160, (1972).

    .. [2] On finding the strongly connected components in a directed graph.
       E. Nuutila and E. Soisalon-Soinen
       Information Processing Letters 49(1): 9-14, (1994)..

    r   éÿÿÿÿé   TFN)ÚsetÚiterÚ_adjÚappendÚminÚpopÚaddÚupdate)ÚGÚpreorderÚlowlinkÚ	scc_foundÚ	scc_queueÚiÚvÚ	neighborsÚsourceÚqueueÚdoneÚwÚsccÚks                 ú|/var/www/ramen.bs-engineer-server.com/venv/lib/python3.12/site-packages/networkx/algorithms/components/strongly_connected.pyr   r      sÍ  è ø€ ðv €HØ€GÜ“€IØ€IØ	€AØ-.Ö/¨�”D˜Ÿ™ ™“OÑ#Ð/€IÐ/Øó ,ˆØ˜Ò"Ø�HˆEÚØ˜"‘I�Ø˜HÑ$Ø˜A™�AØ"#�H˜Q‘KØ�Ø" 1™ò �AØ Ò(ØŸ™ QœØ$˜Ùð	ñ
 Ø!)¨!¡�G˜A‘JØŸV™V A™Yò L˜Ø IÒ-Ø'¨™{¨X°a©[Ò8Ü-0°'¸!±*¸gÀa¹jÐ1IÓ-J ¨¢
ä-0°'¸!±*¸hÀq¹kÐ1JÓ-K ¨¢
ðLð —I‘I”KØ˜q‘z X¨a¡[Ò0Ø ˜c˜Ù'¨H°Y¸r±]Ñ,CÀhÈqÁkÒ,QØ )§¡£˜AØŸG™G AœJñ (¨H°Y¸r±]Ñ,CÀhÈqÁkÓ,Qð "×(Ñ(¨Ô-Ø!›	à!×(Ñ(¨Ô+õ9 ñ,ùò 0ùs4   ‚E3™ E.¹E3ÁE3Á!E3Á.6E3Â%BE3Ä?)E3Å*	E3c              #   ó8  K  — t        t        j                  | j                  d¬«      |¬«      «      }t	        |«      }t        «       }|rÏt	        |«      |k  rÀ|j                  «       }||v rŒ%|h}|j                  |«       |g}|r{t	        |«      |k  rm|j                  «       }| j                  |   D ]:  }	|	|vsŒ|j                  |	«       |j                  |	«       |j                  |	«       Œ< |rt	        |«      |k  rŒm|–— |rt	        |«      |k  rŒ¾yyyy­w)aš  Generate nodes in strongly connected components of graph.

    Parameters
    ----------
    G : NetworkX Graph
        A directed graph.

    source : node, optional (default=None)
        Specify a node from which to start the depth-first search.
        If not provided, the algorithm will start from an arbitrary node.

    Yields
    ------
    set
        A set of all nodes in a strongly connected component of `G`.

    Raises
    ------
    NetworkXNotImplemented
        If `G` is undirected.

    NetworkXError
        If `source` is not a node in `G`.

    Examples
    --------
    Generate a list of strongly connected components of a graph:

    >>> G = nx.cycle_graph(4, create_using=nx.DiGraph())
    >>> nx.add_cycle(G, [10, 11, 12])
    >>> sorted(nx.kosaraju_strongly_connected_components(G), key=len, reverse=True)
    [{0, 1, 2, 3}, {10, 11, 12}]

    If you only want the largest component, it's more efficient to
    use `max()` instead of `sorted()`.

    >>> max(nx.kosaraju_strongly_connected_components(G), key=len)
    {0, 1, 2, 3}

    See Also
    --------
    strongly_connected_components

    Notes
    -----
    Uses Kosaraju's algorithm.
    F)Úcopy)r   N)
ÚlistÚnxÚdfs_postorder_nodesÚreverseÚlenr   r   r   r   r   )
r   r   ÚpostÚnÚseenÚrÚnewÚstackr   r    s
             r#   r   r   r   sø   è ø€ ôd ”×&Ñ& q§y¡y°e yÓ'<ÀVÔLÓM€DÜˆD‹	€AÜ‹5€DÙ
”3�t“9˜q’=Ø�H‰H‹JˆØ�‰9ØØˆcˆØ�‰�ŒØ�ˆÙœ˜D›	 AšØ—	‘	“ˆAØ—V‘V˜A‘Yò $�Ø˜D’=Ø—G‘G˜A”JØ—H‘H˜Q”KØ—L‘L •Oð	$ñ œ˜D›	 A›ð Š	ñ ”3�t“9˜q”=ˆ$�=ˆ$ùs   ‚B8DÂ;ADÄDÄDc                 ó8   — t        d„ t        | «      D «       «      S )aµ  Returns number of strongly connected components in graph.

    Parameters
    ----------
    G : NetworkX graph
       A directed graph.

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

    Raises
    ------
    NetworkXNotImplemented
        If G is undirected.

    Examples
    --------
    >>> G = nx.DiGraph(
    ...     [(0, 1), (1, 2), (2, 0), (2, 3), (4, 5), (3, 4), (5, 6), (6, 3), (6, 7)]
    ... )
    >>> nx.number_strongly_connected_components(G)
    3

    See Also
    --------
    strongly_connected_components
    number_connected_components
    number_weakly_connected_components

    Notes
    -----
    For directed graphs only.
    c              3   ó    K  — | ]  }d –— Œ y­w)r   N© )Ú.0r!   s     r#   ú	<genexpr>z7number_strongly_connected_components.<locals>.<genexpr>Þ   s   è ø€ Ò=�SŒqÑ=ùs   ‚)Úsumr   ©r   s    r#   r   r   ¸   s   € ôL Ñ=Ô9¸!Ó<Ô=Ó=Ð=ó    c                 óš   — t        | «      dk(  rt        j                  d«      ‚t        t        t	        | «      «      «      t        | «      k(  S )aW  Test directed graph for strong connectivity.

    A directed graph is strongly connected if and only if every vertex in
    the graph is reachable from every other vertex.

    Parameters
    ----------
    G : NetworkX Graph
       A directed graph.

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

    Examples
    --------
    >>> G = nx.DiGraph([(0, 1), (1, 2), (2, 3), (3, 0), (2, 4), (4, 2)])
    >>> nx.is_strongly_connected(G)
    True
    >>> G.remove_edge(2, 3)
    >>> nx.is_strongly_connected(G)
    False

    Raises
    ------
    NetworkXNotImplemented
        If G is undirected.

    See Also
    --------
    is_weakly_connected
    is_semiconnected
    is_connected
    is_biconnected
    strongly_connected_components

    Notes
    -----
    For directed graphs only.
    r   z-Connectivity is undefined for the null graph.)r*   r'   ÚNetworkXPointlessConceptÚnextr   r7   s    r#   r   r   á   sG   € ôX ˆ1ƒv�‚{Ü×)Ñ)Ø?ó
ð 	
ô ŒtÔ1°!Ó4Ó5Ó6¼#¸a»&Ñ@Ð@r8   T)Úreturns_graphc                 óÆ  ‡‡— |€t        j                  | «      }i Ši }t        j                  «       }‰|j                  d<   t	        | «      dk(  r|S t        |«      D ]$  \  Š}||‰<   ‰j                  ˆfd„|D «       «       Œ& ‰dz   }|j                  t        |«      «       |j                  ˆfd„| j                  «       D «       «       t        j                  ||d«       |S )a�  Returns the condensation of G.

    The condensation of G is the graph with each of the strongly connected
    components contracted into a single node.

    Parameters
    ----------
    G : NetworkX DiGraph
       A directed graph.

    scc:  list or generator (optional, default=None)
       Strongly connected components. If provided, the elements in
       `scc` must partition the nodes in `G`. If not provided, it will be
       calculated as scc=nx.strongly_connected_components(G).

    Returns
    -------
    C : NetworkX DiGraph
       The condensation graph C of G.  The node labels are integers
       corresponding to the index of the component in the list of
       strongly connected components of G.  C has a graph attribute named
       'mapping' with a dictionary mapping the original nodes to the
       nodes in C to which they belong.  Each node in C also has a node
       attribute 'members' with the set of original nodes in G that
       form the SCC that the node in C represents.

    Raises
    ------
    NetworkXNotImplemented
        If G is undirected.

    Examples
    --------
    Contracting two sets of strongly connected nodes into two distinct SCC
    using the barbell graph.

    >>> G = nx.barbell_graph(4, 0)
    >>> G.remove_edge(3, 4)
    >>> G = nx.DiGraph(G)
    >>> H = nx.condensation(G)
    >>> H.nodes.data()
    NodeDataView({0: {'members': {0, 1, 2, 3}}, 1: {'members': {4, 5, 6, 7}}})
    >>> H.graph["mapping"]
    {0: 0, 1: 0, 2: 0, 3: 0, 4: 1, 5: 1, 6: 1, 7: 1}

    Contracting a complete graph into one single SCC.

    >>> G = nx.complete_graph(7, create_using=nx.DiGraph)
    >>> H = nx.condensation(G)
    >>> H.nodes
    NodeView((0,))
    >>> H.nodes.data()
    NodeDataView({0: {'members': {0, 1, 2, 3, 4, 5, 6}}})

    Notes
    -----
    After contracting all strongly connected components to a single node,
    the resulting graph is a directed acyclic graph.

    Úmappingr   c              3   ó&   •K  — | ]  }|‰f–— Œ
 y ­w©Nr3   )r4   r,   r   s     €r#   r5   zcondensation.<locals>.<genexpr>_  s   øè ø€ Ò1 !˜˜1”vÑ1ùs   ƒr   c              3   óP   •K  — | ]  \  }}‰|   ‰|   k7  sŒ‰|   ‰|   f–— Œ y ­wr@   r3   )r4   Úur   r>   s      €r#   r5   zcondensation.<locals>.<genexpr>b  s7   øè ø€ ò Ù%) Q¨¸'À!¹*ÈÐPQÉ
Ó:Rˆ�‰�W˜Q‘ZÔ ñùs   ƒ&—&Úmembers)r'   r   ÚDiGraphÚgraphr*   Ú	enumerater   Úadd_nodes_fromÚrangeÚadd_edges_fromÚedgesÚset_node_attributes)r   r!   rC   ÚCÚ	componentÚnumber_of_componentsr   r>   s         @@r#   r   r     sÚ   ù€ ð~ €{Ü×.Ñ.¨qÓ1ˆØ€GØ€GÜ
�
‰
‹€Aà €A‡G�GˆIÑÜ
ˆ1ƒv�‚{ØˆÜ! #›ò 2‰ˆˆ9Øˆ�‰
Ø�‰Ó1 yÔ1Õ1ð2ð ˜q™5ÐØ×Ñ”UÐ/Ó0Ô1Ø×Ñó Ø-.¯W©W«Yôô ô ×Ñ˜1˜g yÔ1Ø€Hr8   r@   )Ú__doc__Únetworkxr'   Únetworkx.utils.decoratorsr   Ú__all__Ú_dispatchabler   r   r   r   r   r3   r8   r#   ú<module>rT      së   ðÙ $ã Ý 9ò€ñ �\Ó"Ø×Ññ^,ó ó #ð^,ñB �\Ó"Ø×ÑòAó ó #ðAñH �\Ó"Ø×Ññ$>ó ó #ð$>ñN �\Ó"Ø×Ññ/Aó ó #ð/Añd �\Ó"Ø€×Ñ Ô%òPó &ó #ñPr8   