ó
    …~i7  ã                   ó–   • S r SSKJr  SSKrSSKJrJrJr  S/r	\" S5      \" S5      \R                  " S	S
9S	\4S j5       5       5       rg)z%
Stoer-Wagner minimum cut algorithm.
é    )ÚisliceNé   )Ú
BinaryHeapÚarbitrary_elementÚnot_implemented_forÚstoer_wagnerÚdirectedÚ
multigraphÚweight)Ú
edge_attrsc           
      óŽ  ^• [        U 5      nUS:  a  [        R                  " S5      e[        R                  " U 5      (       d  [        R                  " S5      e[        R                  " U4S jU R                  SS9 5       5      n SU l        U R                  SS9 H%  u  pEnUS   S	:  d  M  [        R                  " S
5      e   [        S5      n[        U 5      n/ n	[        US-
  5       GHb  n
[        U 5      nU1nU" 5       nX   R                  5        H  u  pVUR                  XVS   * 5        M     [        X:-
  S-
  5       Hp  nUR                  5       S	   nUR                  U5        X   R                  5        H3  u  pVX[;  d  M  UR                  X\R                  US	5      US   -
  5        M5     Mr     UR!                  5       u  p^U* nXç:  a  UnU
nU	R#                  XE45        X   R                  5        H>  u  pæXä:w  d  M  XàU   ;  a  U R%                  XNUS   S9  M)  X   U   S==   US   -  ss'   M@     U R'                  U5        GMe     [        R                  " [)        U	W5      5      n XŸ   S   nU R+                  U5        [        [        R,                  " X5      5      n[/        U5      [/        UU-
  5      4nUU4$ )a	  Returns the weighted minimum edge cut using the Stoer-Wagner algorithm.

Determine the minimum edge cut of a connected graph using the
Stoer-Wagner algorithm. In weighted cases, all weights must be
nonnegative.

The running time of the algorithm depends on the type of heaps used:

============== =============================================
Type of heap   Running time
============== =============================================
Binary heap    $O(n (m + n) \log n)$
Fibonacci heap $O(nm + n^2 \log n)$
Pairing heap   $O(2^{2 \sqrt{\log \log n}} nm + n^2 \log n)$
============== =============================================

Parameters
----------
G : NetworkX graph
    Edges of the graph are expected to have an attribute named by the
    weight parameter below. If this attribute is not present, the edge is
    considered to have unit weight.

weight : string
    Name of the weight attribute of the edges. If the attribute is not
    present, unit weight is assumed. Default value: 'weight'.

heap : class
    Type of heap to be used in the algorithm. It should be a subclass of
    :class:`MinHeap` or implement a compatible interface.

    If a stock heap implementation is to be used, :class:`BinaryHeap` is
    recommended over :class:`PairingHeap` for Python implementations without
    optimized attribute accesses (e.g., CPython) despite a slower
    asymptotic running time. For Python implementations with optimized
    attribute accesses (e.g., PyPy), :class:`PairingHeap` provides better
    performance. Default value: :class:`BinaryHeap`.

Returns
-------
cut_value : integer or float
    The sum of weights of edges in a minimum cut.

partition : pair of node lists
    A partitioning of the nodes that defines a minimum cut.

Raises
------
NetworkXNotImplemented
    If the graph is directed or a multigraph.

NetworkXError
    If the graph has less than two nodes, is not connected or has a
    negative-weighted edge.

Examples
--------
>>> G = nx.Graph()
>>> G.add_edge("x", "a", weight=3)
>>> G.add_edge("x", "b", weight=1)
>>> G.add_edge("a", "c", weight=3)
>>> G.add_edge("b", "c", weight=5)
>>> G.add_edge("b", "d", weight=4)
>>> G.add_edge("d", "e", weight=2)
>>> G.add_edge("c", "y", weight=2)
>>> G.add_edge("e", "y", weight=3)
>>> cut_value, partition = nx.stoer_wagner(G)
>>> cut_value
4
é   zgraph has less than two nodes.zgraph is not connected.c              3   ód   >#   • U  H%  u  po1U:w  d  M  XS UR                  TS5      04v •  M'     g7f)r   é   N)Úget)Ú.0ÚuÚvÚer   s       €Úi/home/mande/repo/quber/.venv/lib/python3.13/site-packages/networkx/algorithms/connectivity/stoerwagner.pyÚ	<genexpr>Ústoer_wagner.<locals>.<genexpr>_   s7   øé € ð Ú<N±°°qÐWXÑRXÓ,ˆ�˜!Ÿ%™% ¨Ó*Ð+Õ,Ò<Nùs   ƒ0“0T)ÚdataNr   r   z#graph has a negative-weighted edge.Úinfr   )r   )ÚlenÚnxÚNetworkXErrorÚis_connectedÚGraphÚedgesÚ__networkx_cache__ÚfloatÚsetÚranger   ÚitemsÚinsertÚpopÚaddr   ÚminÚappendÚadd_edgeÚremove_noder   Úadd_nodeÚ"single_source_shortest_path_lengthÚlist)ÚGr   ÚheapÚnr   r   r   Ú	cut_valueÚnodesÚcontractionsÚiÚAÚhÚjÚwÚ
best_phaseÚ	reachableÚ	partitions    `                r   r   r      sƒ  ø€ ôT 	ˆA‹€AØˆ1ƒuÜ×ÒÐ?Ó@Ð@Ü�?Š?˜1×ÑÜ×ÒÐ8Ó9Ð9ô 	�Šô Ø<=¿G¹GÈ¸GÑ<Nóó 	€Að  €AÔà—7‘7 �7Ó%‰ˆˆaØˆX‰;˜�?Ü×"Ò"Ð#HÓIÐIñ &ô �e“€IÜ�‹F€EØ€Lô �1�q‘5�\ˆä˜aÓ ˆØˆCˆñ ‹FˆØ‘D—J‘J–L‰DˆAØ�H‰H�Q˜8™˜Ö%ñ !ô �q‘u˜q‘yÖ!ˆAØ—‘“˜‘
ˆAØ�E‰E�!ŒHØ™Ÿ
™
ž‘�Ø•:Ø—H‘H˜Q§¡ a¨£¨a°©kÑ 9Ö:ó %ñ "ð �u‰u‹w‰ˆØˆBˆØ‹=ØˆIØˆJà×Ñ˜Q˜FÔ#Ø‘D—J‘J–L‰DˆAØ�vØ˜a™D“=Ø—J‘J˜q¨A¨h©K�JÓ8à‘D˜‘G˜HÓ%¨¨8©Ñ4Õ%ñ !ð 	
�‰�a×ñE ôJ 	�Š”˜ jÓ1Ó2€AØÑ  Ñ#€AØ‡J�Jˆq„MÜ”B×9Ò9¸!Ó?Ó@€IÜ�i“¤$ u¨yÑ'8Ó"9Ð:€Ià�iÐÐó    )Ú__doc__Ú	itertoolsr   Únetworkxr   Úutilsr   r   r   Ú__all__Ú_dispatchabler   © r>   r   Ú<module>rF      s`   ðñõ ã ç GÑ GàÐ
€ñ �ZÓ Ù�\Ó"Ø×Ò˜XÑ&Ø#¨*ó G ó 'ó #ó !ñG r>   