
    h8                     v    S r SSKrSSKJr  S/r\" S5      \" S5      \R                  SS j5       5       5       rg)	z(Functions for finding chains in a graph.    N)not_implemented_forchain_decompositiondirected
multigraphc           
   #   ,  #    S	S jnS nUb  X;  a  [         R                  " SU S35      eU" X5      u  pE[        5       nU HL  nUR                  U5        S UR	                  USS9 5       nU H  u  py[        U" XGX5      5      n
U
v   M     MN     g7f)
u  Returns the chain decomposition of a graph.

The *chain decomposition* of a graph with respect a depth-first
search tree is a set of cycles or paths derived from the set of
fundamental cycles of the tree in the following manner. Consider
each fundamental cycle with respect to the given tree, represented
as a list of edges beginning with the nontree edge oriented away
from the root of the tree. For each fundamental cycle, if it
overlaps with any previous fundamental cycle, just take the initial
non-overlapping segment, which is a path instead of a cycle. Each
cycle or path is called a *chain*. For more information, see [1]_.

Parameters
----------
G : undirected graph

root : node (optional)
   A node in the graph `G`. If specified, only the chain
   decomposition for the connected component containing this node
   will be returned. This node indicates the root of the depth-first
   search tree.

Yields
------
chain : list
   A list of edges representing a chain. There is no guarantee on
   the orientation of the edges in each chain (for example, if a
   chain includes the edge joining nodes 1 and 2, the chain may
   include either (1, 2) or (2, 1)).

Raises
------
NodeNotFound
   If `root` is not in the graph `G`.

Examples
--------
>>> G = nx.Graph([(0, 1), (1, 4), (3, 4), (3, 5), (4, 5)])
>>> list(nx.chain_decomposition(G))
[[(4, 5), (5, 3), (3, 4)]]

Notes
-----
The worst-case running time of this implementation is linear in the
number of nodes and number of edges [1]_.

References
----------
.. [1] Jens M. Schmidt (2013). "A simple test on 2-vertex-
   and 2-edge-connectivity." *Information Processing Letters*,
   113, 241–244. Elsevier. <https://doi.org/10.1016/j.ipl.2013.01.016>

Nc                 r   [         R                  " 5       n/ n[         R                  " XS9 H  u  pEnUS:X  aZ  XE:X  a#  UR                  USS9  UR	                  U5        M4  UR                  XTS9  UR                  XTSS9  UR	                  U5        Mf  US:X  a  XRU   ;  a  UR                  XTSS9  M  M     X#4$ )	a  Builds a directed graph composed of cycles from the given graph.

`G` is an undirected simple graph. `root` is a node in the graph
from which the depth-first search is started.

This function returns both the depth-first search cycle graph
(as a :class:`~networkx.DiGraph`) and the list of nodes in
depth-first preorder. The depth-first search cycle graph is a
directed graph whose edges are the edges of `G` oriented toward
the root if the edge is a tree edge and away from the root if
the edge is a non-tree edge. If `root` is not specified, this
performs a depth-first search on each connected component of `G`
and returns a directed forest instead.

If `root` is not in the graph, this raises :exc:`KeyError`.

)sourceforwardN)parentF)nontreer   T)nxDiGraphdfs_labeled_edgesadd_nodeappendadd_edge)GrootHnodesuvds          L/var/www/html/env/lib/python3.13/site-packages/networkx/algorithms/chains.py_dfs_cycle_forest.chain_decomposition.<locals>._dfs_cycle_forestC   s    > JJL++A;GA!I~ 6JJqJ.LLOJJqJ+JJqUJ3LLO iAqTM

1
. ) <* x    c              3   ~   #    X#;  a/  X4v   UR                  U5        X R                  U   S   p!X#;  a  M/  X4v   g7f)ag  Generate the chain starting from the given nontree edge.

`G` is a DFS cycle graph as constructed by
:func:`_dfs_cycle_graph`. The edge (`u`, `v`) is a nontree edge
that begins a chain. `visited` is a set representing the nodes
in `G` that have already been visited.

This function yields the edges in an initial segment of the
fundamental cycle of `G` starting with the nontree edge (`u`,
`v`) that includes all the edges up until the first node that
appears in `visited`. The tree edges are given by the 'parent'
node attribute. The `visited` set is updated to add each node in
an edge yielded by this function.

r   N)addr   )r   r   r   visiteds       r   _build_chain)chain_decomposition.<locals>._build_chain{   sB       $JKKNggaj*q  d
s   3==z
Root node z is not in graphc              3   >   #    U  H  u  po3(       d  M  X4v   M     g 7fN ).0r   r   r   s       r   	<genexpr>&chain_decomposition.<locals>.<genexpr>   s     K'EGA!!'Es   
r   )datar$   )r   NodeNotFoundsetr   	out_edgeslist)r   r   r   r!   r   r   r    r   edgesr   chains              r   r   r   	   s     t6p. DMoo
4&0@ABB
 !)HA eGAKq{{19{'EKDA aA78EK	 	 s   BBr$   )__doc__networkxr   networkx.utilsr   __all___dispatchabler   r%   r   r   <module>r5      sL    .  . 
! Z \"`  # !`r   