
    h1                     8   S r SSKJr  SSKrSSKJr  / SQr\" S5      \R                  S 5       5       r	\" S5      \R                  S 5       5       r
\" S5      \R                  S	 5       5       r\" S5      \R                  S
 5       5       r\" S5      SS j5       rg)z/Biconnected components and articulation points.    )chainN)not_implemented_for)biconnected_componentsbiconnected_component_edgesis_biconnectedarticulation_pointsdirectedc                     [        U 5      n [        U5      n [        U5        g! [         a     gf = f! [         a    [        U5      [        U 5      :H  s $ f = f)u  Returns True if the graph is biconnected, False otherwise.

A graph is biconnected if, and only if, it cannot be disconnected by
removing only one node (and all edges incident on that node).  If
removing a node increases the number of disconnected components
in the graph, that node is called an articulation point, or cut
vertex.  A biconnected graph has no articulation points.

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

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

Raises
------
NetworkXNotImplemented
    If the input graph is not undirected.

Examples
--------
>>> G = nx.path_graph(4)
>>> print(nx.is_biconnected(G))
False
>>> G.add_edge(0, 3)
>>> print(nx.is_biconnected(G))
True

See Also
--------
biconnected_components
articulation_points
biconnected_component_edges
is_strongly_connected
is_weakly_connected
is_connected
is_semiconnected

Notes
-----
The algorithm to find articulation points and biconnected
components is implemented using a non-recursive depth-first-search
(DFS) that keeps track of the highest level that back edges reach
in the DFS tree.  A node `n` is an articulation point if, and only
if, there exists a subtree rooted at `n` such that there is no
back edge from any successor of `n` that links to a predecessor of
`n` in the DFS tree.  By keeping track of all the edges traversed
by the DFS we can obtain the biconnected components because all
edges of a bicomponent will be traversed consecutively between
articulation points.

References
----------
.. [1] Hopcroft, J.; Tarjan, R. (1973).
   "Efficient algorithms for graph manipulation".
   Communications of the ACM 16: 372–378. doi:10.1145/362248.362272

F)r   nextStopIterationlen)Gbccsbccs      \/var/www/html/env/lib/python3.13/site-packages/networkx/algorithms/components/biconnected.pyr   r      se    B "!$D4jT
   
  "3x3q6!!"s   % 5 
22!AAc              #   4   #    [        U SS9 Sh  vN   g N7f)u  Returns a generator of lists of edges, one list for each biconnected
component of the input graph.

Biconnected components are maximal subgraphs such that the removal of a
node (and all edges incident on that node) will not disconnect the
subgraph.  Note that nodes may be part of more than one biconnected
component.  Those nodes are articulation points, or cut vertices.
However, each edge belongs to one, and only one, biconnected component.

Notice that by convention a dyad is considered a biconnected component.

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

Returns
-------
edges : generator of lists
    Generator of lists of edges, one list for each bicomponent.

Raises
------
NetworkXNotImplemented
    If the input graph is not undirected.

Examples
--------
>>> G = nx.barbell_graph(4, 2)
>>> print(nx.is_biconnected(G))
False
>>> bicomponents_edges = list(nx.biconnected_component_edges(G))
>>> len(bicomponents_edges)
5
>>> G.add_edge(2, 8)
>>> print(nx.is_biconnected(G))
True
>>> bicomponents_edges = list(nx.biconnected_component_edges(G))
>>> len(bicomponents_edges)
1

See Also
--------
is_biconnected,
biconnected_components,
articulation_points,

Notes
-----
The algorithm to find articulation points and biconnected
components is implemented using a non-recursive depth-first-search
(DFS) that keeps track of the highest level that back edges reach
in the DFS tree.  A node `n` is an articulation point if, and only
if, there exists a subtree rooted at `n` such that there is no
back edge from any successor of `n` that links to a predecessor of
`n` in the DFS tree.  By keeping track of all the edges traversed
by the DFS we can obtain the biconnected components because all
edges of a bicomponent will be traversed consecutively between
articulation points.

References
----------
.. [1] Hopcroft, J.; Tarjan, R. (1973).
       "Efficient algorithms for graph manipulation".
       Communications of the ACM 16: 372–378. doi:10.1145/362248.362272

T
componentsN)_biconnected_dfs)r   s    r   r   r   a   s     L  d333s   c              #   p   #    [        U SS9 H$  n[        [        R                  " U5      5      v   M&     g7f)u;
  Returns a generator of sets of nodes, one set for each biconnected
component of the graph

Biconnected components are maximal subgraphs such that the removal of a
node (and all edges incident on that node) will not disconnect the
subgraph. Note that nodes may be part of more than one biconnected
component.  Those nodes are articulation points, or cut vertices.  The
removal of articulation points will increase the number of connected
components of the graph.

Notice that by convention a dyad is considered a biconnected component.

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

Returns
-------
nodes : generator
    Generator of sets of nodes, one set for each biconnected component.

Raises
------
NetworkXNotImplemented
    If the input graph is not undirected.

Examples
--------
>>> G = nx.lollipop_graph(5, 1)
>>> print(nx.is_biconnected(G))
False
>>> bicomponents = list(nx.biconnected_components(G))
>>> len(bicomponents)
2
>>> G.add_edge(0, 5)
>>> print(nx.is_biconnected(G))
True
>>> bicomponents = list(nx.biconnected_components(G))
>>> len(bicomponents)
1

You can generate a sorted list of biconnected components, largest
first, using sort.

>>> G.remove_edge(0, 5)
>>> [len(c) for c in sorted(nx.biconnected_components(G), key=len, reverse=True)]
[5, 2]

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

>>> Gc = max(nx.biconnected_components(G), key=len)

To create the components as subgraphs use:
``(G.subgraph(c).copy() for c in biconnected_components(G))``

See Also
--------
is_biconnected
articulation_points
biconnected_component_edges
k_components : this function is a special case where k=2
bridge_components : similar to this function, but is defined using
    2-edge-connectivity instead of 2-node-connectivity.

Notes
-----
The algorithm to find articulation points and biconnected
components is implemented using a non-recursive depth-first-search
(DFS) that keeps track of the highest level that back edges reach
in the DFS tree.  A node `n` is an articulation point if, and only
if, there exists a subtree rooted at `n` such that there is no
back edge from any successor of `n` that links to a predecessor of
`n` in the DFS tree.  By keeping track of all the edges traversed
by the DFS we can obtain the biconnected components because all
edges of a bicomponent will be traversed consecutively between
articulation points.

References
----------
.. [1] Hopcroft, J.; Tarjan, R. (1973).
       "Efficient algorithms for graph manipulation".
       Communications of the ACM 16: 372–378. doi:10.1145/362248.362272

Tr   N)r   setr   from_iterable)r   comps     r   r   r      s/     r !t4%%%d+,, 5s   46c              #   z   #    [        5       n[        U SS9 H  nX!;  d  M
  UR                  U5        Uv   M!     g7f)u  Yield the articulation points, or cut vertices, of a graph.

An articulation point or cut vertex is any node whose removal (along with
all its incident edges) increases the number of connected components of
a graph.  An undirected connected graph without articulation points is
biconnected. Articulation points belong to more than one biconnected
component of a graph.

Notice that by convention a dyad is considered a biconnected component.

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

Yields
------
node
    An articulation point in the graph.

Raises
------
NetworkXNotImplemented
    If the input graph is not undirected.

Examples
--------

>>> G = nx.barbell_graph(4, 2)
>>> print(nx.is_biconnected(G))
False
>>> len(list(nx.articulation_points(G)))
4
>>> G.add_edge(2, 8)
>>> print(nx.is_biconnected(G))
True
>>> len(list(nx.articulation_points(G)))
0

See Also
--------
is_biconnected
biconnected_components
biconnected_component_edges

Notes
-----
The algorithm to find articulation points and biconnected
components is implemented using a non-recursive depth-first-search
(DFS) that keeps track of the highest level that back edges reach
in the DFS tree.  A node `n` is an articulation point if, and only
if, there exists a subtree rooted at `n` such that there is no
back edge from any successor of `n` that links to a predecessor of
`n` in the DFS tree.  By keeping track of all the edges traversed
by the DFS we can obtain the biconnected components because all
edges of a bicomponent will be traversed consecutively between
articulation points.

References
----------
.. [1] Hopcroft, J.; Tarjan, R. (1973).
       "Efficient algorithms for graph manipulation".
       Communications of the ACM 16: 372–378. doi:10.1145/362248.362272

Fr   N)r   r   add)r   seenarticulations      r   r   r     s8     H 5D(u=#HH\" >s   ;;c           	   #     #    [        5       nU  GH.  nX2;   a  M  US0nUS0nSnUR                  U5        / nX3[        X   5      4/n0 n	U(       a  US   u  pn [        U5      nX:X  a  M"  X;   aE  XM   XK   ::  a:  [	        X[   XM   5      X['   U(       a!  [        U5      XU4'   UR                  X45        Oh[        U5      =X]'   XM'   UR                  U5        UR                  X[        X   5      45        U(       a!  [        U5      XU4'   UR                  X45        U(       a  M  U(       a  GM!  US:  d  GM*  Uv   GM1     g ! [         a    UR                  5         [        U5      S:  a:  X[   XJ   :  a  U(       a  XU4   nX~S  v   X~S 2	 OU
v   [	        X[   XZ   5      XZ'    NU(       a  US-  nU(       a  XU4   nX~S  v   X~S 2	  Nf = f7f)Nr      )	r   r   iterr   minr   appendr   pop)r   r   visitedstart	discoverylowroot_children
edge_stackstack
edge_indexgrandparentparentchildrenchildinds                  r   r   r   R  s     eGAJ	ajE
QX/0
,1"I)K#-X'# '9+<<&)#+y7G&H%8;JJu}5&--vo>47	NBCJ!1KK&LL&ah!@A!47
O
5=1"))6/:% eL zq g < ! -		u:>{i&<<%",&-@"AC",T"22 *4 0 #.-'*3;8H'IC$!Q&M!(f)<=(..&t,#-sc   AGE)G+A	E4G5A(EG&G0G9
GA!G$G&#G	GGG)T)__doc__	itertoolsr   networkxnxnetworkx.utils.decoratorsr   __all___dispatchabler   r   r   r   r        r   <module>r;      s    5   9 Z L  !L^ Z D4  !D4N Z X-  !X-v Z F  !FR Z 7 !7r:   