
    h                        S r SSKJ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.    )Counter)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         N/var/www/html/env/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   V   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$ )	a  Computing a minimum-weight maximal matching of G.

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.

You might worry that adding 1 to each weight would make the algorithm
favor matchings with more edges. But we use the parameter
`maxcardinality=True` in `max_weight_matching` to ensure that the
number of edges in the competing matchings are the same and thus
the optimum does not change due to changes in the number of edges.

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>;  s     2'wq!'s   c              3   8   >#    U  H  u  po1UTU-
  4v   M     g 7fr6   r7   )r8   r   r   r:   
max_weights       r   r;   r<   =  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    f 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.r7   N)__name__
__module____qualname____firstlineno____doc____static_attributes__r7   r   r   NoNoderG     s    ;r   rN   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r6   )rQ   popr(   extend)selfstacktBlossoms      r   leaves+max_weight_matching.<locals>.Blossom.leaves  sJ     "dkkNEIIKa))LL*G %s   AA%#A%r7   N)rH   rI   rJ   rK   rL   	__slots__rZ   rM   )rY   s   r   rY   rP     s    E6		 	r   rY   r   Tr3   r2   ')intlongNc                 R   > TU    TU   -   STU    U   R                  TS5      -  -
  $ )Nr#   r2   )get)r   r:   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 )Nr2   r#   )rb   r(   rU   rZ   append)r:   rX   r   bbaserY   assignLabelbestedgeblossombase	inblossomlabel	labeledgematequeues        r   rj   (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   r2      r   r#   )rg   )r   r:   pathri   rh   rN   rl   rm   rn   ro   rp   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#   r2   r   )rQ   r   rg   reverserZ   r(   rR   	neighborsrb   listvalues)ri   r   r:   bbbvbwrh   rv   edgs
bestedgetonblistkijbj
mybestedgekslackmybestslackrY   r   rk   rl   blossomdualblossomparentrm   rn   ro   rp   rq   rd   s                     r   
addBlossom'max_weight_matching.<locals>.addBlossomC  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#   r2   T)rQ   r(   rZ   rb   indexr*   r   rT   )rh   endstagesr   
entrychildr   jstepr:   pqr   r   rY   	allowedgerj   rk   rl   r   r   rm   rn   ro   rp   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   rg   rT   )rh   r   r   rW   topr   rY   r   rj   rk   rl   r   r   rm   rn   ro   rp   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)Nr2   r   r   )r(   rQ   r   r*   r   )rh   r   rX   r   r   r   r:   xrY   rl   r   rp   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   )
rh   r   r   rW   r   argsrY   rl   r   rp   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 )Nr2   r   r#   )r(   )r   r:   r   r   bsrX   btrY   r   rl   rm   rn   ro   rp   s          r   augmentMatching,max_weight_matching.<locals>.augmentMatchingW  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]   r2   r#   r   )	r@   minr}   r*   r   rb   rg   rz   zip)vdualoffsetr   r   dwtr   	iblossoms	jblossomsbir   r   rh   r   r   r   rc   gnodesrp   r1   r.   s               r   verifyOptimum*max_weight_matching.<locals>.verifyOptimumx  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       @   rt   F)r|   r   r   rb   strtypesplitr)   r   r   clearrR   rT   r{   r   r}   r   r@   rg   keysr!   )+r   r1   r.   	maxweight
allintegerr   r   r   r   rw   r   r   r   r   rh   r   	augmentedr:   r   r   r   ri   	deltatypedelta	deltaedgedeltablossomrY   rN   r   rj   r   rk   rl   r   r   rc   r   rm   rn   ro   rp   rq   rd   s+   ```                       @@@@@@@@@@@@@@@@@r   r
   r
   B  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.   )rL   collectionsr   	itertoolsr   r   networkxr   networkx.utilsr   __all___dispatchabler   r!   r   r   r	   r   r
   r7   r   r   <module>r      s   A  *  . \"Z $  ! #$N2 9 9x : :z 0  0 f \"Z X&7I ' ! #7It \"Z X&{& ' ! #{&r   