§
    bŠtj
  ã                   ó0   — d Z ddlmZ  G d„ d¦  «        ZdS )z
Union-find data structure.
é    )Úgroupsc                   ó2   — e Zd ZdZdd„Zd„ Zd„ Zd„ Zd„ ZdS )	Ú	UnionFindaŒ  Union-find data structure.

    Each unionFind instance X maintains a family of disjoint sets of
    hashable objects, supporting the following two methods:

    - X[item] returns a name for the set containing the given item.
      Each set is named by an arbitrarily-chosen one of its members; as
      long as the set remains unchanged it will keep the same name. If
      the item is not yet part of a set in X, a new singleton set is
      created for it.

    - X.union(item1, item2, ...) merges the sets containing each item
      into a single larger set.  If any item is not yet part of a set
      in X, it is added to X as one of the members of the merged set.

      Union-find data structure. Based on Josiah Carlson's code,
      https://code.activestate.com/recipes/215912/
      with significant additional changes by D. Eppstein.
      http://www.ics.uci.edu/~eppstein/PADS/UnionFind.py

    Nc                 ó\   — |€d}i | _         i | _        |D ]}d| j        |<   || j         |<   ŒdS )z¾Create a new empty union-find structure.

        If *elements* is an iterable, this structure will be initialized
        with the discrete partition on the given set of elements.

        N© é   )ÚparentsÚweights)ÚselfÚelementsÚxs      úW/var/www/html/CA-Chatbot/venv/lib/python3.11/site-packages/networkx/utils/union_find.pyÚ__init__zUnionFind.__init__   sN   € ð ÐØˆHØˆŒØˆŒØð 	 ð 	 ˆAØˆDŒL˜‰OØˆDŒL˜‰OˆOð	 ð 	 ó    c                 óà   — || j         vr|| j         |<   d| j        |<   |S g }| j         |         }||k    r*|                     |¦  «         |}| j         |         }||k    °*|D ]}|| j         |<   Œ|S )z:Find and return the name of the set containing the object.r   )r	   r
   Úappend)r   ÚobjectÚpathÚrootÚancestors        r   Ú__getitem__zUnionFind.__getitem__.   s�   € ð ˜œÐ%Ð%Ø#)ˆDŒL˜Ñ Ø#$ˆDŒL˜Ñ ØˆMð ˆØŒ|˜FÔ#ˆØ�fŠnˆnØ�KŠK˜ÑÔÐØˆFØ”< Ô'ˆDð �fŠnˆnð ð 	*ð 	*ˆHØ%)ˆDŒL˜Ñ"Ð"Øˆr   c                 ó*   — t          | j        ¦  «        S )zBIterate through all items ever found or unioned by this structure.)Úiterr	   )r   s    r   Ú__iter__zUnionFind.__iter__D   s   € å�D”LÑ!Ô!Ð!r   c              #   ó†   K  — | j         D ]
}| |         }Œt          | j         ¦  «                             ¦   «         E d{V —† dS )a]  Iterates over the sets stored in this structure.

        For example::

            >>> partition = UnionFind("xyz")
            >>> sorted(map(sorted, partition.to_sets()))
            [['x'], ['y'], ['z']]
            >>> partition.union("x", "y")
            >>> sorted(map(sorted, partition.to_sets()))
            [['x', 'y'], ['z']]

        N)r	   r   Úvalues)r   r   Ú_s      r   Úto_setszUnionFind.to_setsH   sX   è è € ð ”ð 	ð 	ˆAØ�Q”ˆAˆAå˜$œ,Ñ'Ô'×.Ò.Ñ0Ô0Ð0Ð0Ð0Ð0Ð0Ð0Ð0Ð0Ð0r   c                 ó  ‡ — t          t          ˆ fd„|D ¦   «         ˆ fd„d¬¦  «        ¦  «        }	 t          |¦  «        }n# t          $ r Y dS w xY w|D ],}‰ j        |xx         ‰ j        |         z  cc<   |‰ j        |<   Œ-dS )z8Find the sets containing the objects and merge them all.c                 ó    •— h | ]
}‰|         ’ŒS r   r   )Ú.0r   r   s     €r   ú	<setcomp>z"UnionFind.union.<locals>.<setcomp>`   s   ø€ Ð*Ð*Ð*˜Q��a”Ð*Ð*Ð*r   c                 ó   •— ‰j         |          S ©N)r
   )Úrr   s    €r   ú<lambda>z!UnionFind.union.<locals>.<lambda>`   s   ø€ ¸$¼,Àq¼/€ r   T)ÚkeyÚreverseN)r   ÚsortedÚnextÚStopIterationr
   r	   )r   ÚobjectsÚrootsr   r%   s   `    r   ÚunionzUnionFind.union[   sÌ   ø€ õ ÝØ*Ð*Ð*Ð* 'Ð*Ñ*Ô*Ð0IÐ0IÐ0IÐ0IÐSWðñ ô ñ
ô 
ˆð
	Ý˜‘;”;ˆDˆDøÝð 	ð 	ð 	ØˆFˆFð	øøøð ð 	#ð 	#ˆAØŒL˜ÐÐÔ $¤,¨q¤/Ñ1ÐÐÑØ"ˆDŒL˜‰OˆOð	#ð 	#s   ±A Á
AÁAr$   )	Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r.   r   r   r   r   r      sn   € € € € € ðð ð, ð  ð  ð  ðð ð ð,"ð "ð "ð1ð 1ð 1ð&#ð #ð #ð #ð #r   r   N)r2   Únetworkx.utilsr   r   r   r   r   ú<module>r4      s_   ððð ð "Ð !Ð !Ð !Ð !Ð !ðb#ð b#ð b#ð b#ð b#ñ b#ô b#ð b#ð b#ð b#r   