
    hg                         S 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	 r
g)
zWeakly connected components.    N)not_implemented_for)"number_weakly_connected_componentsweakly_connected_componentsis_weakly_connected
undirectedc              #      #    [        5       n[        U 5      nU  H4  nX1;  d  M
  [        [        XU5      5      nUR                  U5        Uv   M6     g7f)aR  Generate weakly connected components of G.

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

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

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

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

>>> G = nx.path_graph(4, create_using=nx.DiGraph())
>>> nx.add_path(G, [10, 11, 12])
>>> [
...     len(c)
...     for c in sorted(nx.weakly_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_cc = max(nx.weakly_connected_components(G), key=len)

See Also
--------
connected_components
strongly_connected_components

Notes
-----
For directed graphs only.

N)setlen
_plain_bfsupdate)Gseennvcs        a/var/www/html/env/lib/python3.13/site-packages/networkx/algorithms/components/weakly_connected.pyr   r      sH     ` 5DAA=JqQ'(AKKNG	 s
   A/Ac                 8    [        S [        U 5       5       5      $ )a  Returns the number of weakly connected components in G.

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

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

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

Examples
--------
>>> G = nx.DiGraph([(0, 1), (2, 1), (3, 4)])
>>> nx.number_weakly_connected_components(G)
2

See Also
--------
weakly_connected_components
number_connected_components
number_strongly_connected_components

Notes
-----
For directed graphs only.

c              3   &   #    U  H  nS v   M	     g7f)   N ).0wccs     r   	<genexpr>5number_weakly_connected_components.<locals>.<genexpr>k   s     ;:Sq:s   )sumr   r   s    r   r   r   F   s    J ;7:;;;    c                     [        U 5      S:X  a  [        R                  " S5      e[        [        [	        U 5      5      5      [        U 5      :H  $ )a  Test directed graph for weak connectivity.

A directed graph is weakly connected if and only if the graph
is connected when the direction of the edge between nodes is ignored.

Note that if a graph is strongly connected (i.e. the graph is connected
even when we account for directionality), it is by definition weakly
connected as well.

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

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

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

Examples
--------
>>> G = nx.DiGraph([(0, 1), (2, 1)])
>>> G.add_node(3)
>>> nx.is_weakly_connected(G)  # node 3 is not connected to the graph
False
>>> G.add_edge(2, 3)
>>> nx.is_weakly_connected(G)
True

See Also
--------
is_strongly_connected
is_semiconnected
is_connected
is_biconnected
weakly_connected_components

Notes
-----
For directed graphs only.

r   z-Connectivity is undefined for the null graph.)r
   nxNetworkXPointlessConceptnextr   r   s    r   r   r   n   sG    d 1v{))?
 	
 t/234A>>r   c              #     #    U R                   nU R                  nU1nU/nUv   U(       a  Un/ nU H  nX8    H0  n	X;  d  M
  UR                  U	5        UR                  U	5        U	v   M2     XH    H0  n	X;  d  M
  UR                  U	5        UR                  U	5        U	v   M2     [	        U5      U:X  d  M    g   U(       a  M  gg7f)zkA fast BFS node generator

The direction of the edge between nodes is ignored.

For directed graphs only.

N)_succ_predaddappendr
   )
r   r   sourceGsuccGpredr   	nextlevel	thislevelr   ws
             r   r   r      s      GGEGGE8DI
L
		AX=HHQK$$Q'G	 
 X=HHQK$$Q'G	 
 4yA~  )s   =C4C;7C6CC)__doc__networkxr   networkx.utils.decoratorsr   __all___dispatchabler   r   r   r   r   r   r   <module>r2      s    "  9 \"4  #4n \"#<  ##<L \"5?  #5?pr   