
    hz                         S r SSKJr  SSKrSSKJr  SS/r\" S5      \R                  S 5       5       r	\R                  S	 5       r
g)
z
Dominance algorithms.
    )reduceN)not_implemented_forimmediate_dominatorsdominance_frontiers
undirectedc                   ^^	 X;  a  [         R                  " S5      eX0m	[        [         R                  " X5      5      n[	        U5       VVs0 s H  u  p4XC_M	     snnmUR                  5         UR                  5         UU	4S jnSnU(       aO  SnU H>  n[        UU	4S jU R                  U    5       5      nUT	;  d  T	U   U:w  d  M7  UT	U'   SnM@     U(       a  MO  T	$ s  snnf )a  Returns the immediate dominators of all nodes of a directed graph.

Parameters
----------
G : a DiGraph or MultiDiGraph
    The graph where dominance is to be computed.

start : node
    The start node of dominance computation.

Returns
-------
idom : dict keyed by nodes
    A dict containing the immediate dominators of each node reachable from
    `start`.

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

NetworkXError
    If `start` is not in `G`.

Notes
-----
Except for `start`, the immediate dominators are the parents of their
corresponding nodes in the dominator tree.

Examples
--------
>>> G = nx.DiGraph([(1, 2), (1, 3), (2, 5), (3, 4), (4, 5)])
>>> sorted(nx.immediate_dominators(G, 1).items())
[(1, 1), (2, 1), (3, 1), (4, 3), (5, 1)]

References
----------
.. [1] Cooper, Keith D., Harvey, Timothy J. and Kennedy, Ken.
       "A simple, fast dominance algorithm." (2006).
       https://hdl.handle.net/1911/96345
zstart is not in Gc                    > X:w  aE  TU    TU   :  a  TU    n TU    TU   :  a  M  TU    TU   :  a  TU   nTU    TU   :  a  M  X:w  a  ME  U $ N )uvdfnidoms     O/var/www/html/env/lib/python3.13/site-packages/networkx/algorithms/dominance.py	intersect'immediate_dominators.<locals>.intersectC   sh    fa&3q6/G a&3q6/a&3q6/G a&3q6/ f
     TFc              3   6   >#    U  H  oT;   d  M
  Uv   M     g 7fr
   r   ).0r   r   s     r   	<genexpr>'immediate_dominators.<locals>.<genexpr>O   s     )LYt)!!Ys   		)	nxNetworkXErrorlistdfs_postorder_nodes	enumeratepopreverser   pred)
Gstartorderir   r   changednew_idomr   r   s
           @@r   r   r      s    X ~233>D''12E%e,
-,DA14,
-C	IIK	MMO G
Ai)LQVVAY)LMH}Q8 3"Q	  ' K+ .s   C!c                 N   [         R                  " X5      nU Vs0 s H  o3[        5       _M     nnU Hi  n[        U R                  U   5      S:  d  M!  U R                  U    H5  nXR;   d  M
  XRU   :w  d  M  XE   R                  U5        X%   nXRU   :w  a  M!  M7     Mk     U$ s  snf )a\  Returns the dominance frontiers of all nodes of a directed graph.

Parameters
----------
G : a DiGraph or MultiDiGraph
    The graph where dominance is to be computed.

start : node
    The start node of dominance computation.

Returns
-------
df : dict keyed by nodes
    A dict containing the dominance frontiers of each node reachable from
    `start` as lists.

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

NetworkXError
    If `start` is not in `G`.

Examples
--------
>>> G = nx.DiGraph([(1, 2), (1, 3), (2, 5), (3, 4), (4, 5)])
>>> sorted((u, sorted(df)) for u, df in nx.dominance_frontiers(G, 1).items())
[(1, []), (2, [5]), (3, [5]), (4, [5]), (5, [])]

References
----------
.. [1] Cooper, Keith D., Harvey, Timothy J. and Kennedy, Ken.
       "A simple, fast dominance algorithm." (2006).
       https://hdl.handle.net/1911/96345
   )r   r   setlenr   add)r    r!   r   r   dfr   s         r   r   r   W   s    L ""1,D 	!DqSU(DB	!qvvay>QVVAY9Aw,		! G Aw,   I 
"s   B")__doc__	functoolsr   networkxr   networkx.utilsr   __all___dispatchabler   r   r   r   r   <module>r2      sd      .!#8
9 \"E  #EP / /r   