
    9i%                        S r SSKJrJr  SSKrSSKJr  / SQr\" S5      \" S5      \R                  S 5       5       5       r
S	 r\R                  S
 5       r\R                  S 5       r\R                  S 5       r\" S5      \" S5      \R                  " SS9SS j5       5       5       r\" S5      \" S5      \R                  " SS9SS j5       5       5       rg)z;Functions for computing and verifying matchings in a graph.    )combinationsrepeatN)not_implemented_for)is_matchingis_maximal_matchingis_perfect_matchingmax_weight_matchingmin_weight_matchingmaximal_matching
multigraphdirectedc                     [        5       n[        5       nU R                  5        H>  nUu  pEXB;  d  M  XR;  d  M  XE:w  d  M  UR                  U5        UR                  U5        M@     U$ )aI  Find a maximal matching in the graph.

A matching is a subset of edges in which no node occurs more than once.
A maximal matching cannot add more edges and still be a matching.

Parameters
----------
G : NetworkX graph
    Undirected graph

Returns
-------
matching : set
    A maximal matching of the graph.

Examples
--------
>>> G = nx.Graph([(1, 2), (1, 3), (2, 3), (2, 4), (3, 5), (4, 5)])
>>> sorted(nx.maximal_matching(G))
[(1, 2), (3, 5)]

Notes
-----
The algorithm greedily selects a maximal matching M of the graph G
(i.e. no superset of M exists). It runs in $O(|E|)$ time.
)setedgesaddupdateGmatchingnodesedgeuvs         \/var/www/html/land-doc-ocr/venv/lib/python3.13/site-packages/networkx/algorithms/matching.pyr   r      sW    < uHEE	 >anLLLL  O    c                     [        5       nU R                  5        HD  nUu  p4XC4U;   d  X!;   a  M  X4:X  a  [        R                  " SU 35      eUR	                  U5        MF     U$ )a  Converts matching dict format to matching set format

Converts a dictionary representing a matching (as returned by
:func:`max_weight_matching`) to a set representing a matching (as
returned by :func:`maximal_matching`).

In the definition of maximal matching adopted by NetworkX,
self-loops are not allowed, so the provided dictionary is expected
to never have any mapping from a key to itself. However, the
dictionary is expected to have mirrored key/value pairs, for
example, key ``u`` with value ``v`` and key ``v`` with value ``u``.

z%Selfloops cannot appear in matchings )r   itemsnxNetworkXErrorr   )r   r   r   r   r   s        r   matching_dict_to_setr    <   sc     EE 6U?dm6""%J4&#QRR		$ ! Lr   c                    [        U[        5      (       a  [        U5      n[        5       nU H  n[	        U5      S:w  a  [
        R                  " SU 35      eUu  pEX@;  d  XP;  a  [
        R                  " SU S35      eXE:X  a    gU R                  XE5      (       d    gXB;   d  XR;   a    gUR                  U5        M     g)a[  Return True if ``matching`` is a valid matching of ``G``

A *matching* in a graph is a set of edges in which no two distinct
edges share a common endpoint. Each node is incident to at most one
edge in the matching. The edges are said to be independent.

Parameters
----------
G : NetworkX graph

matching : dict or set
    A dictionary or set representing a matching. If a dictionary, it
    must have ``matching[u] == v`` and ``matching[v] == u`` for each
    edge ``(u, v)`` in the matching. If a set, it must have elements
    of the form ``(u, v)``, where ``(u, v)`` is an edge in the
    matching.

Returns
-------
bool
    Whether the given set or dictionary represents a valid matching
    in the graph.

Raises
------
NetworkXError
    If the proposed matching has an edge to a node not in G.
    Or if the matching is not a collection of 2-tuple edges.

Examples
--------
>>> G = nx.Graph([(1, 2), (1, 3), (2, 3), (2, 4), (3, 5), (4, 5)])
>>> nx.is_maximal_matching(G, {1: 3, 2: 4})  # using dict to represent matching
True

>>> nx.is_matching(G, {(1, 3), (2, 4)})  # using set to represent matching
True

   matching has non-2-tuple edge matching contains edge  with node not in GFT	
isinstancedictr    r   lenr   r   has_edger   r   s         r   r   r   U   s    R (D!!'1EEt9>""%CD6#JKK:""%<TFBU#VWW6zz!:T  r   c                 B   [        U[        5      (       a  [        U5      n[        5       n[        5       nU H  n[	        U5      S:w  a  [
        R                  " SU 35      eUu  pVXP;  d  X`;  a  [
        R                  " SU S35      eXV:X  a    gU R                  XV5      (       d    gXS;   d  Xc;   a    gUR                  U5        UR                  U5        UR                  Xe45        M     U R                   H#  u  pVXV4U;  d  M  XS;  d  M  Xc;  d  M  XV:w  d  M#    g   g)a  Return True if ``matching`` is a maximal matching of ``G``

A *maximal matching* in a graph is a matching in which adding any
edge would cause the set to no longer be a valid matching.

Parameters
----------
G : NetworkX graph

matching : dict or set
    A dictionary or set representing a matching. If a dictionary, it
    must have ``matching[u] == v`` and ``matching[v] == u`` for each
    edge ``(u, v)`` in the matching. If a set, it must have elements
    of the form ``(u, v)``, where ``(u, v)`` is an edge in the
    matching.

Returns
-------
bool
    Whether the given set or dictionary represents a valid maximal
    matching in the graph.

Examples
--------
>>> G = nx.Graph([(1, 2), (1, 3), (2, 3), (3, 4), (3, 5)])
>>> nx.is_maximal_matching(G, {(1, 2), (3, 4)})
True

r"   r#   r$   r%   FT)r'   r(   r    r   r)   r   r   r*   r   r   r   )r   r   r   r   r   r   r   s          r   r   r      s    > (D!!'1EEEEt9>""%CD6#JKK:""%<TFBU#VWW6zz!:T		$		1& $ 6~!.QV	 
 r   c                    [        U[        5      (       a  [        U5      n[        5       nU H  n[	        U5      S:w  a  [
        R                  " SU 35      eUu  pEX@;  d  XP;  a  [
        R                  " SU S35      eXE:X  a    gU R                  XE5      (       d    gXB;   d  XR;   a    gUR                  U5        M     [	        U5      [	        U 5      :H  $ )a#  Return True if ``matching`` is a perfect matching for ``G``

A *perfect matching* in a graph is a matching in which exactly one edge
is incident upon each vertex.

Parameters
----------
G : NetworkX graph

matching : dict or set
    A dictionary or set representing a matching. If a dictionary, it
    must have ``matching[u] == v`` and ``matching[v] == u`` for each
    edge ``(u, v)`` in the matching. If a set, it must have elements
    of the form ``(u, v)``, where ``(u, v)`` is an edge in the
    matching.

Returns
-------
bool
    Whether the given set or dictionary represents a valid perfect
    matching in the graph.

Examples
--------
>>> G = nx.Graph([(1, 2), (1, 3), (2, 3), (2, 4), (3, 5), (4, 5), (4, 6)])
>>> my_match = {1: 2, 3: 5, 4: 6}
>>> nx.is_perfect_matching(G, my_match)
True

r"   r#   r$   r%   Fr&   r   s         r   r   r      s    @ (D!!'1EEt9>""%CD6#JKK:""%<TFBU#VWW6zz!:T  u:Qr   weight)
edge_attrsc                   ^ [        U R                  5      S:X  a  [        U SUS9$ U R                  USS9nS[        S U 5       5      -   m[        R
                  " 5       nU4S jU 5       nUR                  XAS9  [        USUS9$ )	ae  Compute a minimum-weight maximum-cardinality matching of `G`.

The minimum-weight maximum-cardinality matching is the matching
that has the minimum weight among all maximum-cardinality matchings.

Use the maximum-weight algorithm with edge weights subtracted
from the maximum weight of all edges.

A matching is a subset of edges in which no node occurs more than once.
The weight of a matching is the sum of the weights of its edges.
A maximal matching cannot add more edges and still be a matching.
The cardinality of a matching is the number of matched edges.

This method replaces the edge weights with 1 plus the maximum edge weight
minus the original edge weight.

new_weight = (max_weight + 1) - edge_weight

then runs :func:`max_weight_matching` with the new weights.
The max weight matching with these new weights corresponds
to the min weight matching using the original weights.
Adding 1 to the max edge weight keeps all edge weights positive
and as integers if they started as integers.

Read the documentation of `max_weight_matching` for more information.

Parameters
----------
G : NetworkX graph
  Undirected graph

weight: string, optional (default='weight')
   Edge data key corresponding to the edge weight.
   If key not found, uses 1 as weight.

Returns
-------
matching : set
    A minimal weight matching of the graph.

See Also
--------
max_weight_matching
r   T)maxcardinalityr-      )datadefaultc              3   ,   #    U  H
  u    pUv   M     g 7fN ).0_ws      r   	<genexpr>&min_weight_matching.<locals>.<genexpr>7  s     2'wq!'s   c              3   8   >#    U  H  u  po1UTU-
  4v   M     g 7fr5   r6   )r7   r   r   r9   
max_weights       r   r:   r;   9  s     ;7aJN#7s   r-   )r)   r   r	   maxr   Graphadd_weighted_edges_from)r   r-   G_edgesInvGr   r=   s        @r   r
   r
     s    ` 177|q"1T&IIgg61g-GS2'222J88:D;7;E   6tDHHr   c                   ^ ^^^^^^^^^ ^!^"^#^$^%^&^'^(^)^*  " S S5      m " U4S jS5      m[        T 5      m$T$(       d
  [        5       $ SnSnT R                  SS9 HV  u  pVnUR                  TS5      nXV:w  a  X:  a  UnU=(       a)    [	        [        U5      5      R                  S	5      S   S
;   nMX     0 m(0 m&0 m'[        [        T$T$5      5      m%[        [        T$[        S5      5      5      m"[        [        T$T$5      5      m 0 m[        [        T$[        U5      5      5      m#0 m!0 m/ m)U U#U4S jm*UUUU U%U&U'U(U)4	S jmUU U%U&U'U(4S jn	UU UU U!U"U%U&U'U(U)U*4S jn
UUUUU U!U"U%U&U'U(4S jnUU U"U(4S jmUUU U%U&U'U(4S jnU U!U"U#U$U(UU4S jn T&R                  5         T'R                  5         TR                  5         T! H
  nSUl        M     TR                  5         / T)SS& T$ H,  nUT(;  d  M  T&R                  T%U   5      b  M"  T" USS5        M.     Sn T)(       Ga  U(       Gd  T)R                  5       nT&T%U      S:X  d   eT R                  U5       GHO  nUU:X  a  M  T%U   nT%U   nUU:X  a  M  UU4T;  a  T*" UU5      nUS::  a  S=TUU4'   TUU4'   UU4T;   a  T&R                  U5      c  T" USU5        Mi  T&R                  U5      S:X  a'  U	" UU5      nUTLa  U
" UUU5        M  U" UU5        Sn  OT&R                  U5      c  T&U   S:X  d   eST&U'   UU4T'U'   M  M  T&R                  U5      S:X  a+  TR                  U5      b  WT*" TU   6 :  a
  UU4TU'   GM  GM  T&R                  U5      b  GM'  TR                  U5      b  WT*" TU   6 :  d  GMH  UU4TU'   GMR     T)(       a
  U(       d  GM  U(       a  GOSnS=n=nnT(       d  Sn[        T#R                  5       5      nT R!                  5        HM  nT&R                  T%U   5      b  M  TR                  U5      c  M.  T*" TU   6 nUS:X  d  UU:  d  MD  UnSnTU   nMO     T" Hr  nT"U   b  M  T&R                  U5      S:X  d  M"  TR                  U5      c  M6  T*" TU   6 nU(       a  US-  S:X  d   eUS-  nOUS-  nUS:X  d  UU:  d  Mi  UnSnTU   nMt     T! H<  nT"U   b  M  T&R                  U5      S:X  d  M"  US:X  d  T!U   U:  d  M3  T!U   nSnUnM>     US:X  a.  T(       d   eSn[#        S[        T#R                  5       5      5      nT$ HQ  nT&R                  T%U   5      S:X  a  T#U==   U-  ss'   M*  T&R                  T%U   5      S:X  d  MD  T#U==   U-  ss'   MS     T! HS  nT"U   b  M  T&R                  U5      S:X  a  T!U==   U-  ss'   M/  T&R                  U5      S:X  d  MF  T!U==   U-  ss'   MU     US:X  a  OUS:X  a3  Uu  nnT&T%U      S:X  d   eS=TUU4'   TUU4'   T)R%                  U5        OHUS:X  a3  Uu  nnS=TUU4'   TUU4'   T&T%U      S:X  d   eT)R%                  U5        OUS:X  a	  U" US5        GMa  T( H  nT(T(U      U:X  a  M   e   U(       d  O^[        T!R'                  5       5       H>  nUT!;  a  M  T"U   b  M  T&R                  U5      S:X  d  M*  T!U   S:X  d  M5  U" US5        M@     GMh  U(       a  U" 5         [)        T(5      $ )a  Compute a maximum-weighted matching of G.

A matching is a subset of edges in which no node occurs more than once.
The weight of a matching is the sum of the weights of its edges.
A maximal matching cannot add more edges and still be a matching.
The cardinality of a matching is the number of matched edges.

Parameters
----------
G : NetworkX graph
  Undirected graph

maxcardinality: bool, optional (default=False)
   If maxcardinality is True, compute the maximum-cardinality matching
   with maximum weight among all maximum-cardinality matchings.

weight: string, optional (default='weight')
   Edge data key corresponding to the edge weight.
   If key not found, uses 1 as weight.


Returns
-------
matching : set
    A maximal matching of the graph.

 Examples
--------
>>> G = nx.Graph()
>>> edges = [(1, 2, 6), (1, 3, 2), (2, 3, 1), (2, 4, 7), (3, 5, 9), (4, 5, 3)]
>>> G.add_weighted_edges_from(edges)
>>> sorted(nx.max_weight_matching(G))
[(2, 4), (5, 3)]

Notes
-----
If G has edges with weight attributes the edge data are used as
weight values else the weights are assumed to be 1.

This function takes time O(number_of_nodes ** 3).

If all edge weights are integers, the algorithm uses only integer
computations.  If floating point weights are used, the algorithm
could return a slightly suboptimal matching due to numeric
precision errors.

This method is based on the "blossom" method for finding augmenting
paths and the "primal-dual" method for finding a matching of maximum
weight, both methods invented by Jack Edmonds [1]_.

Bipartite graphs can also be matched using the functions present in
:mod:`networkx.algorithms.bipartite.matching`.

References
----------
.. [1] "Efficient Algorithms for Finding Maximum Matching in Graphs",
   Zvi Galil, ACM Computing Surveys, 1986.
c                       \ rS rSrSrSrg)#max_weight_matching.<locals>.NoNodei  z-Dummy value which is different from any node.r6   N)__name__
__module____qualname____firstlineno____doc____static_attributes__r6   r   r   NoNoderF     s    ;r   rM   c                   .   > \ rS rSrSr/ SQrU 4S jrSrg)$max_weight_matching.<locals>.Blossomi  z7Representation of a non-trivial blossom or sub-blossom.)childsr   mybestedgesc              3      >#    / U R                   QnU(       aK  UR                  5       n[        UT5      (       a  UR                  UR                   5        OUv   U(       a  MJ  g g 7fr5   )rP   popr'   extend)selfstacktBlossoms      r   leaves+max_weight_matching.<locals>.Blossom.leaves  sJ     "dkkNEIIKa))LL*G %s   AA%#A%r6   N)rG   rH   rI   rJ   rK   	__slots__rY   rL   )rX   s   r   rX   rO     s    E6		 	r   rX   r   Tr2   r1   ')intlongNc                 R   > TU    TU   -   STU    U   R                  TS5      -  -
  $ )Nr"   r1   )get)r   r9   r   dualvarr-   s     r   slack"max_weight_matching.<locals>.slack  s3    qzGAJ&QqT!W[[-C)CCCr   c                 z  >	 T	U    nT
R                  U 5      c  T
R                  U5      b   eU=T
U '   T
U'   Ub  X 4=TU '   TU'   O
S =TU '   TU'   S =TU '   TU'   US:X  aC  [        UT5      (       a   TR                  UR                  5       5        g TR	                  U5        g US:X  a  TU   nT" TU   SU5        g g )Nr1   r"   )ra   r'   rT   rY   append)r9   rW   r   bbaserX   assignLabelbestedgeblossombase	inblossomlabel	labeledgematequeues        r   ri   (max_weight_matching.<locals>.assignLabel  s    aLyy|#		!(<<<a58=+,&0IaL9Q<*..IaL9Q<$((hqk6!W%%QXXZ(Q!V q>DT
At, r   c                 T  > / nTnU TLa  TU    nTU   S-  (       a  TU   nOwTU   S:X  d   eUR                  U5        STU'   T	U   c  TU   T
;  d   eTn O4T	U   S   T
TU      :X  d   eT	U   S   n TU    nTU   S:X  d   eT	U   S   n UTLa  XpU TLa  M  U H  nSTU'   M
     U$ )N   r1      r   r"   )rf   )r   r9   pathrh   rg   rM   rk   rl   rm   rn   ro   s        r   scanBlossom(max_weight_matching.<locals>.scanBlossom  s    vo!AQx!|"1~8q= =KKNE!H|#"1~T111 |A${1~*>>>>aLOaLQx1}$}aLO1/ vo2 AE!H  r   c                   > TU    nTU   nTU   nT" 5       nU TU'   S TU'   UTU'   / =Ul         nX4/=Ul        nXC:w  ad  UTU'   UR                  U5        UR                  TU   5        TU   S:X  d  TU   S:X  a  TU   S   TTU      :X  d   eTU   S   nTU   nXC:w  a  Md  UR                  U5        UR                  5         UR                  5         XS:w  ao  UTU'   UR                  U5        UR                  TU   S   TU   S   45        TU   S:X  d  TU   S:X  a  TU   S   TTU      :X  d   eTU   S   nTU   nXS:w  a  Mo  TU   S:X  d   eSTU'   TU   TU'   STU'   UR	                  5        H%  nTTU      S:X  a  TR                  U5        UTU'   M'     0 n	U H  n[        UT5      (       ae  UR                  b  UR                  n
S Ul        OmUR	                  5        VVs/ s H&  nTR                  U5        H  o!U:w  d  M
  X4PM     M(     n
nnO)TR                  U5       Vs/ s H  o$U:w  d  M
  XB4PM     n
nU
 HQ  nUu  pTU   U:X  a  XpTU   nX:w  d  M  TR                  U5      S:X  d  M5  X;  d  T" X5      T" X   6 :  d  MM  XU'   MS     S TU'   GM     [        U	R                  5       5      Ul        S nS TU'   UR                   H  nT" U6 nUb  UW:  d  M  UnUnM     UTU'   g s  snnf s  snf )Nr"   r1   r   )rP   r   rf   reverserY   r'   rQ   	neighborsra   listvalues)rh   r   r9   bbbvbwrg   ru   edgs
bestedgetonblistkijbj
mybestedgekslackmybestslackrX   r   rj   rk   blossomdualblossomparentrl   rm   rn   ro   rp   rc   s                     r   
addBlossom'max_weight_matching.<locals>.addBlossom?  sn   t_q\q\IAab4&!$h !M"KKOKK	"&9>b	Q9R=#3tKO7L#L  "a A1B h 	Bh !M"KKOKK2q)9R=+;<=9>b	Q9R=#3tKO7L#L  "a A1B h RyA~~a }	!AAYq\"a' QIaL  
B"g&&>>-^^F%)BN
 )+		(31Q[[^TUv^  F ,-;;r?F?aAg'2'?FQ<1$qq\G		"*.5;
AW3W%&rN   HRL7 8 Z..01
AAYF!Vk%9
$	 
 !7 Gs   +K8K8/	K><K>c                    > UUUU	U
UUUUUU4S jnU" X5      /nU(       a?  US   nU H  nUR                  U" XQ5      5          O   UR                  5         U(       a  M>  g g )Nc              3     >#    U R                    HR  nS TU'   [        UT5      (       a4  U(       a  TU   S:X  a  Uv   M/  UR                  5        H  nUTU'   M
     MM  UTU'   MT     U(       Gd  TR                  U 5      S:X  Ga   TTU    S      nU R                   R	                  U5      nUS-  (       a  U[        U R                   5      -  nSnOSnTU    u  p7US:w  a  US:X  a  U R                  U   u  pOU R                  US-
     u  pS TU'   S TU	'   T" USU5        S=TX4'   TX4'   XV-  nUS:X  a  U R                  U   u  p7OU R                  US-
     u  psS=TX74'   TXs4'   XV-  nUS:w  a  M  U R                   U   n
S=TU'   TU
'   X74=TU'   TU
'   S TU
'   XV-  nU R                   U   U:w  a  U R                   U   nTR                  U5      S:X  a  XV-  nM=  [        UT5      (       a0  UR                  5        H  nTR                  U5      (       d  M    O   OUnTR                  U5      (       a6  TU   S:X  d   eTU   U:X  d   eS TU'   S TTTU      '   T" USTU   S   5        XV-  nU R                   U   U:w  a  M  TR                  U S 5        TR                  U S 5        TR                  U S 5        TU 	 TU 	 TU 	 g 7f)Nr   r"   r1   T)rP   r'   rY   ra   indexr)   r   rS   )rg   endstagesr   
entrychildr   jstepr9   pqr   r~   rX   	allowedgeri   rj   rk   r   r   rl   rm   rn   ro   s               r   _recurse<max_weight_matching.<locals>.expandBlossom.<locals>._recurse  s    XX#'a a))KNa$7!"A+,IaL ", $%IaL  %))A,!"3 'y|A7
HHNN:.q5QXX&AE E |1fz wwqz1 wwq1u~#E!H#E!H1a(<@@Iqf%	1&(9JAz wwqz1 wwq1u~<@@Iqf%	1&(9JA% 1f* XXa['((a5901v5	!y}#
hhqkZ/ !Byy}) 
 !"g..!#A$yy|| % "-  yy||$Qx1},}(|r111#'a7;d;r?34#Aq)A,q/:JA1 hhqkZ/4 IIaMM!T"LLD!a AAs   E-K2B"KA*KA Kr   rf   rS   )rg   r   r   rV   topr   rX   r   ri   rj   rk   r   r   rl   rm   rn   ro   s         r   expandBlossom*max_weight_matching.<locals>.expandBlossom  s[    [	 [	D !&')CXa23  		 er   c                    > UUUU	4S jnU" X5      /nU(       a<  US   nU H  nUR                  U" U6 5          O   UR                  5         U(       a  M;  g g )Nc              3     >#    UnT
U   U :w  a  T
U   nT
U   U :w  a  M  [        UT5      (       a  X!4v   U R                  R                  U5      =p4US-  (       a  U[        U R                  5      -  nSnOSnUS:w  a  XE-  nU R                  U   nUS:X  a  U R                  U   u  pgOU R                  US-
     u  pv[        UT5      (       a  X&4v   XE-  nU R                  U   n[        UT5      (       a  X'4v   UTU'   UTU'   US:w  a  M  U R                  US  U R                  S U -   U l        U R                  US  U R                  S U -   U l        T	U R                  S      T	U '   T	U    U:X  d   eg 7f)Nr1   r   r   )r'   rP   r   r)   r   )rg   r   rW   r   r   r   r9   xrX   rk   r   ro   s           r   r   =max_weight_matching.<locals>.augmentBlossom.<locals>._recurse  s     A"a'!!$  "a' !W%%fHHNN1%%A1uS]" q&
HHQKA:771:DAq771q5>DAa))&L
HHQKa))&LQQ# q&& xx|ahhrl2AHggabkAGGBQK/AG(!5KNq>Q&&&s   E7C-E7A)E7r   r   )
rg   r   r   rV   r   argsrX   rk   r   ro   s
         r   augmentBlossom+max_weight_matching.<locals>.augmentBlossom  sW    )	' )	'` ! )CXt_-  		 er   c                 h  > X4X44 H  u  p# T
U   nTU   S:X  d   eTU   c	  T	U   T;  d  TU   S   TT	U      :X  d   e[        UT5      (       a  T" XB5        UTU'   TU   c  M_  TU   S   nT
U   nTU   S:X  d   eTU   u  p#T	U   U:X  d   e[        UT5      (       a  T" Xc5        UTU'   M     g )Nr1   r   r"   )r'   )r   r9   r   r   bsrW   btrX   r   rk   rl   rm   rn   ro   s          r   augmentMatching,max_weight_matching.<locals>.augmentMatchingS  s   VaV$DA q\RyA~%~!"-+b/2MbM!$[_(==  b'**"2)QR=(bM!$q\RyA~%~ }"2!+++b'**"2)Q3 	 %r   c                  r  > T(       a%  [        S[        TR                  5       5      * 5      n OSn [        TR                  5       5      U -   S:  d   e[        T5      S:X  d  [        TR                  5       5      S:  d   eTR	                  SS9 GH$  u  pnUR                  TS5      nX:X  a  M   TU   TU   -   SU-  -
  nU/nU/nTUS      b"  UR                  TUS      5        TUS      b  M"  TUS      b"  UR                  TUS      5        TUS      b  M"  UR                  5         UR                  5         [        Xg5       H  u  pX:w  a    OUSTU   -  -  nM     US:  d   eTR                  U5      U:X  d  TR                  U5      U:X  d  GM  TU   U:X  a	  TU   U:X  d   eUS:X  a  GM%   e   T H  n
U
T;   a  M  TU
   U -   S:X  a  M   e   T H[  nTU   S:  d  M  [        UR                  5      S-  S:X  d   eUR                  SS S2    H  u  pTU   U:X  a  TU   U:X  a  M   e   M]     g )Nr   Tr\   r1   r"   r   )	r?   minr|   r)   r   ra   rf   ry   zip)vdualoffsetr   r   dwtr   	iblossoms	jblossomsbir   r   rg   r   r   r   rb   gnodesro   r0   r-   s               r   verifyOptimum*max_weight_matching.<locals>.verifyOptimumt  s`    a#gnn&6"7!78KK7>>#${2a777;1$K,>,>,@(AQ(FFF wwDw)GA!vq!Bv
WQZ'!b&0AII	".:  y}!=>  	".:	".:  y}!=>  	".:i38QR(( 4 6M6xx{a488A;!#3Aw!|Q144Avv) *, AI'!*{":a"???  A1~!177|a'1,,,GGADqDMDA7a<DGqL88 * r   r"   r   g       @   rs   F)r{   r   r   ra   strtypesplitr(   r   r   clearrQ   rS   rz   r   r|   r   r?   rf   keysr    )+r   r0   r-   	maxweight
allintegerr   r   r   r   rv   r   r   r   r   rg   r   	augmentedr9   r~   r   r   rh   	deltatypedelta	deltaedgedeltablossomrX   rM   r   ri   r   rj   rk   r   r   rb   r   rl   rm   rn   ro   rp   rc   s+   ```                       @@@@@@@@@@@@@@@@@r   r	   r	   >  sx   X< < 8 !WFu IJ777%aUU616bnITSb]%8%8%=a%@O%S
	 & D E I S()I
 VVD\23M s66*+K H 3vvi012G
 K
 I ED
- -2   J\! \! \!~o oh= =B B)9 )9Z  	 	A AM 
 	 a A599Yq\#:#BAq$' 
 	 	IIKYq\*a/// QAAv "1B"1BRx 1vY.!&q!!Q;DHHIq!f-	1a&0A1v* 99R=0 (1a0"YYr]a/ $/q!#4D#61 !+4A 6 !01 5,-	 %"YYq\1
 $)9>1>'(E!H,-q6IaL 2 2!+ $<<+3vxPR|@T7T,-q6HRL 8U1- $<<?2fuhqk?R6R+,a&HQKi ( 		x  I/33E3I "	GNN,- WWY99Yq\*2x||A7Rx{+A B!e) !$%	$,QK	  #!!$,		!) Q3"HQK0F! &
q000"aK"SL B!e) !$%	$,QK	 #$ !!!$,		!)"bKNU,B'NE !I#$L ! B &%~	As7>>#345 99Yq\*a/AJ%'JYYy|,1AJ%'J  ! #+yy|q(#A%/1*#A%/ ! A~a"AYq\*a///8<<	1a&!Iq!f$5Qa"A8<<	1a&!Iq!f$5Yq\*a///QalE2Q Z AQ=A%%%   k&&()A#Q'EIIaLA,=+a.TUBUa&	 *c p %%r   r>   )Fr-   )rK   	itertoolsr   r   networkxr   networkx.utilsr   __all___dispatchabler   r    r   r   r   r
   r	   r6   r   r   <module>r      s   A *  . \"Z $  ! #$N2 9 9x : :z 0  0 f \"Z X&4I ' ! #4In \"Z X&{& ' ! #{&r   