
    daf*              
           d dl  dee   deeee   f   deee      fdZdeee   eee      f   deeee         fdZdeeee   f   d	ee   d
edee	e      fdZ
y)    )*verticesedgesreturnc              #      K   t               g i g dt        dt        t        t              ffd| D ]  }|vs |      E d{     y7 w)a  Compute Strongly Connected Components of a directed graph.

    Args:
      vertices: the labels for the vertices
      edges: for each vertex, gives the target vertices of its outgoing edges

    Returns:
      An iterator yielding strongly connected components, each
      represented as a set of vertices.  Each input vertex will occur
      exactly once; vertices not part of a SCC are returned as
      singleton sets.

    From https://code.activestate.com/recipes/578507-strongly-connected-components-of-a-directed-graph/.
    vr   c              3     K   t              | <   j                  |        j                  |           |    D ]D  }|vr |      E d {    |vs|   d   k  s)j                          |   d   k  rF d   |    k(  r?j                          t        |    d        }|    d = j	                  |       | y y 7 w)N)lenappendpopsetupdate)	r   wscc
boundariesdfsr   
identifiedindexstacks	      9/root/Python-3.12.4/Tools/peg_generator/pegen/sccutils.pyr   z*strongly_connected_components.<locals>.dfs   s     u:aQ%(#q 	%A~q6!!*$AhB/NN$ AhB/		% b>U1X%NNeE!HJ'(CeAhj!c"I & "s%   ACC	CC%CACN)r   strIteratorSet)r   r   r   r   r   r   r   r   s    ` @@@@@r   strongly_connected_componentsr      sh     " 5JEEJs xC)  &  E>1vs   ?AAAAdatac              #     K   | j                         D ]  \  }}|j                  |        t        j                  | j	                          t        | j                               z
  D ]  }t               | |<    	 | j                         D ch c]
  \  }}|r	| }}}|sn0| | j                         D ci c]  \  }}||vs|||z
   } }}X| r
J d| z         yc c}}w c c}}w w)a`  Topological sort.

    Args:
      data: A map from SCCs (represented as frozen sets of strings) to
            sets of SCCs, its dependencies.  NOTE: This data structure
            is modified in place -- for normalization purposes,
            self-dependencies are removed and entries representing
            orphans are added.

    Returns:
      An iterator yielding sets of SCCs that have an equivalent
      ordering.  NOTE: The algorithm doesn't care about the internal
      structure of SCCs.

    Example:
      Suppose the input has the following structure:

        {A: {B, C}, B: {D}, C: {D}}

      This is normalized to:

        {A: {B, C}, B: {D}, C: {D}, D: {}}

      The algorithm will yield the following values:

        {D}
        {B, C}
        {A}

    From https://code.activestate.com/recipes/577413-topological-sort/history/1/.
    z%A cyclic dependency exists amongst %rN)itemsdiscardr   unionvalueskeys)r   kr   itemdepreadys         r   topsortr'   4   s     F 

 1			!		4;;=)C		,<< UT

'+zz|?)$3??59ZZ\W	cTQVEVsU{"WW  C<tCC8t @ Xs*   B
C*
CCC*8C$C$C*graphr   startc              #      K   ||v s	J ||f       | j                         k  sJ | j                         z
          j                         D ci c]   \  }}||v s||D ch c]	  }||v s| c}" c}}} | v sJ dt        dt        t           dt        t        t              f fd |g       E d{    yc c}w c c}}}w 7 w)aa  Find cycles in SCC emanating from start.

    Yields lists of the form ['A', 'B', 'C', 'A'], which means there's
    a path from A -> B -> C -> A.  The first item is always the start
    argument, but the last item may be another element, e.g.  ['A',
    'B', 'C', 'B'] means there's a path from A to B and there's a
    cycle from B to C and back.
    nodepathr   c              3   n   K   | |v r	|| gz    y || gz   }|    D ]  } ||      E d {     y 7 w)N )r+   r,   childr   r(   s      r   r   zfind_cycles_in_scc.<locals>.dfsx   sN     4<$-tf}4[ 	(E5$'''	('s   (535N)r"   r   r   Listr   )r(   r   r)   srcdstsdstr   s   `     @r   find_cycles_in_sccr4   d   s      C<%%%<%**,2ejjl 22 HM{{}cc)#tX[_bXbS$53#*355cEE>>(# (T#Y (8DI+> ( 5"~ 6c sC   ACCC#	C-C1C6AC;C<CCCN)typingAbstractSetr   Dictr   r   r   Iterabler'   r0   r4   r.       r   <module>r:      s    +#+'+CS1A,A'B+k#+\-D
{3[%5!66
7-Dk+c*+,-D`[%%&-8-=FId3ir9   