Ë
    ©Ó^jQ  ã                   óâ   — d Z ddgZddlmZ ddlZ ej                  dd¬«      d„ «       Z ej                  d¬	«      d
„ «       Z ed«      d„ «       Z	 ed«      d„ «       Z
dd„Zd„ Zd„ Zd„ Zd„ Zy)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              #   ó4  K  — | dk  rt        d«      ‚| dk(  ry| dk(  rt        j                  d«      –— yt        t	        | dz  dz   «      «      t        t	        d| dz   dz  «      «      z   }|�)t        |«      }|�t        |«      –— t        |«      }|�Œ(yy­w)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     úr/var/www/ramen.bs-engineer-server.com/venv/lib/python3.12/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                 ó8   — | dk  rt        d«      ‚t        | «      S )aK  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                 óº   — d}t        | dz   «      D ]  }|t        |«      t        | |z
  «      z  z  }Œ! | dz  dk(  r|t        | dz  «      z  }t        | «      |dz  z
  S )z4Implements OEIS A000055 (number of unlabeled trees).r   r
   r   ©r   Ú_rooted_trees)ÚnÚvalueÚks      r   r   r   t   so   € ð €EÜ�1�q‘5‹\ò 9ˆØ”˜qÓ!¤M°!°a±%Ó$8Ñ8Ñ8‰ð9àˆ1�u�‚zØ”˜q A™vÓ&Ñ&ˆÜ˜Ó˜e q™jÑ(Ð(r   c                 óº   — | dk  r| S d}t        d| «      D ]<  }t        d| «      D ]+  }||z  dk(  sŒ||t        |«      z  t        | |z
  «      z  z  }Œ- Œ> || dz
  z  S )z;Implements OEIS A000081 (number of unlabeled rooted trees).r   r   r
   r   )r   r   ÚjÚds       r   r   r   €   s�   € ð 	ˆ1‚uØˆØ€EÜ�1�a‹[ò EˆÜ�q˜!“ò 	EˆAØ�1‰u˜‹zØ˜œ]¨1Ó-Ñ-´¸aÀ!¹eÓ0DÑDÑD‘ñ	EðEð �Q˜‘UÑÐr   c                 ó  — |€$t        | «      dz
  }| |   dk(  r|dz  }| |   dk(  rŒ|dk(  ry|dz
  }| |   | |   dz
  k7  r|dz  }| |   | |   dz
  k7  rŒt        | «      }t        |t        |«      «      D ]  }|||z
  |z      ||<   Œ |S )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Ø
�a‰.˜K¨™N¨QÑ.Ò
.Ø	ˆQ‰ˆð �a‰.˜K¨™N¨QÑ.Ó
.ä�+Ó€FÜ�1”c˜&“kÓ"ò &ˆØ˜1˜q™5 1™9Ñ%ˆˆqŠ	ð&à€Mr   c                 óŠ  — t        | «      \  }}t        |«      }t        |«      }||k\  }|r=||k(  r8t        |«      t        |«      kD  rd}nt        |«      t        |«      k(  r||kD  rd}|r| S t        |«      }t        | |«      }| |   dkD  r7t        |«      \  }}	t        |«      }
t	        d|
dz   «      }||t        |«       d |S )zGOne 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›)Ò#¨¨tªØˆEáØÐô �‹IˆÜ)¨)°QÓ7ˆØ�Q‰<˜!ÒÜ!,¨]Ó!;ÑˆH�hÜ! (›mˆOÜ˜1˜o°Ñ1Ó2ˆFØ,2ˆMœ3˜v›;˜,˜.Ð)ØÐr   c                 ó&  — d}d}t        t        | «      «      D ]  }| |   dk(  sŒ|r|} nd}Œ |€t        | «      }t        d|«      D �cg c]
  }| |   dz
  ‘Œ }}dgt        |t        | «      «      D �cg c]  }| |   ‘Œ	 c}z   }||fS c c}w c c}w )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ˆF�1‰I˜‹MÐ/€DÐ/Øˆ3¤U¨1¬c°&«kÓ%:Ö; �&˜“)Ò;Ñ;€DØ�$ˆ<Ðùò 0ùÚ;s   Á
B	Á4Bc                 óP  — t        t        | «      «      D �cg c]  }dgt        | «      z  ‘Œ }}g }t        t        | «      «      D ]Y  }| |   }|r?|d   }| |   }||k\  r |j                  «        |d   }| |   }||k\  rŒ dx||   |<   ||   |<   |j                  |«       Œ[ |S c c}w )z\Create 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Ø˜Q‘iˆGØ˜WÒ$Ø—	‘	”Ø˜"‘I�Ø  ™)�ð ˜WÓ$ð +,Ð+ˆF�1‰I�a‰L˜6 !™9 Q™<Ø�‰�Q�ð
ð €Mùò =s   —B#c                 ó  — t        j                  «       }g }t        t        | «      «      D ][  }| |   }|rA|d   }| |   }||k\  r |j	                  «        |d   }| |   }||k\  rŒ |j                  ||«       |j                  |«       Œ] |S )zVCreate 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Ø˜Q‘iˆGØ˜WÒ$Ø—	‘	”Ø˜"‘I�Ø  ™)�ð ˜WÓ$ð �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   