ó
    †~iQ  ã                   óØ   • S r SS/rSSKJr  SSKr\R                  " SSS9S 5       r\R                  " SS	9S
 5       r\" S5      S 5       r	\" S5      S 5       r
SS jrS rS rS rS rg)a  
Implementation of the Wright, Richmond, Odlyzko and McKay (WROM)
algorithm for the enumeration of all non-isomorphic free trees of a
given order.  Rooted trees are represented by level sequences, i.e.,
lists in which the i-th element specifies the distance of vertex i to
the root.

Únonisomorphic_treesÚnumber_of_nonisomorphic_treesé    )Ú	lru_cacheNT)ÚgraphsÚreturns_graphc              #   óD  #   • U S:  a  [        S5      eU S:X  a  gU S:X  a  [        R                  " S5      v •  g[        [	        U S-  S-   5      5      [        [	        SU S-   S-  5      5      -   nUb,  [        U5      nUb  [        U5      v •  [        U5      nUb  M+  gg7f)a|  Generate nonisomorphic trees of specified `order`.

Parameters
----------
order : int
   order of the desired tree(s)

Yields
------
`networkx.Graph` instances
   A tree with `order` number of nodes that is not isomorphic to any other
   yielded tree.

Raises
------
ValueError
   If `order` is negative.

Examples
--------
There are 11 unique (non-isomorphic) trees with 7 nodes.

>>> n = 7
>>> nit_list = list(nx.nonisomorphic_trees(n))
>>> len(nit_list) == nx.number_of_nonisomorphic_trees(n) == 11
True

All trees yielded by the generator have the specified order.

>>> all(len(G) == n for G in nx.nonisomorphic_trees(n))
True

Each tree is nonisomorphic to every other tree yielded by the generator.
>>> seen = []
>>> for G in nx.nonisomorphic_trees(n):
...     assert not any(nx.is_isomorphic(G, H) for H in seen)
...     seen.append(G)

See Also
--------
number_of_nonisomorphic_trees
r   úorder must be non-negativeNé   é   )Ú
ValueErrorÚnxÚempty_graphÚlistÚrangeÚ
_next_treeÚ_layout_to_graphÚ_next_rooted_tree)ÚorderÚlayouts     Úd/home/mande/repo/quber/.venv/lib/python3.13/site-packages/networkx/generators/nonisomorphic_trees.pyr   r      s¢   é € ðX ˆqƒyÜÐ5Ó6Ð6Ø�ƒzàà�ƒzÜ�nŠn˜QÓÒØä”%˜ ™
 Q™Ó'Ó(¬4´°a¸%À!¹)ÈÑ9IÓ0JÓ+KÑK€Fà
Ñ
Ü˜FÓ#ˆØÑÜ" 6Ó*Ò*Ü& vÓ.ˆFð	 Õ
ùs   ‚BB ÂB )r   c                 ó:   • U S:  a  [        S5      e[        U 5      $ )aó  Returns the number of nonisomorphic trees of the specified `order`.

Based on an algorithm by Alois P. Heinz in
`OEIS entry A000055 <https://oeis.org/A000055>`_. Complexity is ``O(n ** 3)``.

Parameters
----------
order : int
   Order of the desired tree(s).

Returns
-------
int
   Number of nonisomorphic trees with `order` number of nodes.

Raises
------
ValueError
   If `order` is negative.

Examples
--------
>>> nx.number_of_nonisomorphic_trees(10)
106

See Also
--------
nonisomorphic_trees
r   r	   )r   Ú_unlabeled_trees)r   s    r   r   r   P   s"   € ð> ˆqƒyÜÐ5Ó6Ð6Ü˜EÓ"Ð"ó    c                 ó¾   • Sn[        U S-   5       H  nU[        U5      [        X-
  5      -  -  nM!     U S-  S:X  a  U[        U S-  5      -  n[        U 5      US-  -
  $ )z4Implements OEIS A000055 (number of unlabeled trees).r   r
   r   ©r   Ú_rooted_trees)ÚnÚvalueÚks      r   r   r   t   sh   € ð €EÜ�1�q‘5Ž\ˆØ”˜qÓ!¤M°!±%Ó$8Ñ8Ñ8Šñ àˆ1�u�ƒzØ”˜q A™vÓ&Ñ&ˆÜ˜Ó˜e q™jÑ(Ð(r   c                 óÀ   • U S:  a  U $ Sn[        SU 5       H>  n[        SU 5       H+  nX#-  S:X  d  M  X[        U5      -  [        X-
  5      -  -  nM-     M@     XS-
  -  $ )z;Implements OEIS A000081 (number of unlabeled rooted trees).r   r   r
   r   )r   r   ÚjÚds       r   r   r   €   sk   € ð 	ˆ1ƒuØˆØ€EÜ�1�aŽ[ˆÜ�q˜!–ˆAØ‰u˜�zØœ]¨1Ó-Ñ-´¸a¹eÓ0DÑDÑD’ó ñ ð ˜‘UÑÐr   c                 ó  • Uc%  [        U 5      S-
  nX   S:X  a  US-  nX   S:X  a  M  US:X  a  gUS-
  nX   X   S-
  :w  a  US-  nX   X   S-
  :w  a  M  [        U 5      n[        U[        U5      5       H  nX4U-
  U-      X4'   M     U$ )z0One iteration of the Beyer-Hedetniemi algorithm.Nr
   r   )Úlenr   r   )ÚpredecessorÚpÚqÚresultÚis        r   r   r   Ž   s­   € ð 	�yÜ�Ó˜qÑ ˆØ‰n Ó!Ø�‰FˆAð ‰n Õ!àˆAƒvØà	ˆA‰€AØ
‰.˜K™N¨QÑ.Ó
.Ø	ˆQ‰ˆð ‰.˜K™N¨QÑ.Õ
.ä�+Ó€FÜ�1”c˜&“kÖ"ˆØ˜q™5 1™9Ñ%ˆ‹	ñ #à€Mr   c                 ó˜  • [        U 5      u  p[        U5      n[        U5      nXC:¬  nU(       a?  XC:X  a:  [        U5      [        U5      :”  a  SnO[        U5      [        U5      :X  a  X:”  a  SnU(       a  U $ [        U5      n[        X5      nX   S:”  a5  [        U5      u  p‰[        U5      n
[	        SU
S-   5      nX·[        U5      * S& U$ )zCOne iteration of the Wright, Richmond, Odlyzko and McKay
algorithm.Fr   r
   N)Ú_split_treeÚmaxr$   r   r   )Ú	candidateÚleftÚrestÚleft_heightÚrest_heightÚvalidr&   Únew_candidateÚnew_leftÚnew_restÚnew_left_heightÚsuffixs               r   r   r   ¡   sË   € ô ˜YÓ'�J€Dô �d“)€KÜ�d“)€KØÑ&€Eæ�Ó+ô ˆt‹9”s˜4“yÓ Ø‰Eô �‹Yœ#˜d›)Ó#¨«ØˆEæØÐô �‹IˆÜ)¨)Ó7ˆØ‰<˜!ÓÜ!,¨]Ó!;ÑˆHÜ! (›mˆOÜ˜1˜o°Ñ1Ó2ˆFØ,2œ3˜v›;˜,˜.Ð)ØÐr   c                 ó>  • SnSn[        [        U 5      5       H  nX   S:X  d  M  U(       a  Un  OSnM     Uc  [        U 5      n[        SU5       Vs/ s H
  o0U   S-
  PM     nnS/[        U[        U 5      5       Vs/ s H  o0U   PM	     sn-   nXE4$ s  snf s  snf )z—Returns a tuple of two layouts, one containing the left
subtree of the root vertex, and one containing the original tree
with the left subtree removed.FNr
   Tr   )r   r$   )r   Ú	one_foundÚmr)   r.   r/   s         r   r+   r+   È   s¤   € ð
 €IØ€AÜ”3�v“;ÖˆØ‰9˜�>ÞØ�Ùà ’	ñ  ð 	�yÜ�‹Kˆä#(¨¨A¤;Ó/¢;˜a�1‰I˜ŒM¡;€DÐ/Øˆ3¤U¨1¬c°&«kÔ%:Ó;Ò%: ˜”)Ñ%:Ñ;Ñ;€DØˆ<Ðùò 0ùÚ;s   ÁBÁ?Bc                 ó\  • [        [        U 5      5       Vs/ s H  nS/[        U 5      -  PM     nn/ n[        [        U 5      5       H[  nX   nU(       a<  US   nX   nXd:¼  a   UR                  5         US   nX   nXd:¼  a  M   S=X!   U'   X%   U'   UR                  U5        M]     U$ s  snf )zXCreate the adjacency matrix for the tree specified by the
given layout (level sequence).r   éÿÿÿÿr
   )r   r$   ÚpopÚappend)r   r)   r(   ÚstackÚi_levelr!   Új_levels          r   Ú_layout_to_matrixrB   ß   s¶   € ô */¬s°6«{Ô);Ó<Ò); Aˆqˆc”C˜“KÔÑ);€FÐ<Ø€EÜ”3�v“;ÖˆØ‘)ˆÞØ�b‘	ˆAØ‘iˆGØÓ$Ø—	‘	”Ø˜"‘I�Ø ™)�ð Õ$ð +,Ð+ˆF‰I�a‰L˜6™9 Q™<Ø�‰�QŽñ  ð €Mùò =s   —B)c                 ó   • [         R                  " 5       n/ n[        [        U 5      5       H^  nX   nU(       a?  US   nX   nXd:¼  a   UR	                  5         US   nX   nXd:¼  a  M   UR                  X55        UR                  U5        M`     U$ )zRCreate a NetworkX Graph for the tree specified by the
given layout(level sequence)r<   )r   ÚGraphr   r$   r=   Úadd_edger>   )r   ÚGr?   r)   r@   r!   rA   s          r   r   r   ó   sˆ   € ô 	�Š‹
€AØ€EÜ”3�v“;ÖˆØ‘)ˆÞØ�b‘	ˆAØ‘iˆGØÓ$Ø—	‘	”Ø˜"‘I�Ø ™)�ð Õ$ð �J‰J�qÔØ�‰�QŽñ  ð €Hr   )N)Ú__doc__Ú__all__Ú	functoolsr   Únetworkxr   Ú_dispatchabler   r   r   r   r   r   r+   rB   r   © r   r   Ú<module>rM      s©   ðñð !Ð"AÐ
B€å ã ð ×Ò˜¨TÑ2ñ;/ó 3ð;/ð| ×Ò˜Ññ #ó ð #ñF ˆ4ƒñ)ó ð)ñ ˆ4ƒñ
ó ð
ôò&$òNò.ó(r   