ó
    †~i  ã                   ó\   • S SK Jr  S SKrSS/rS	S jr\R                  " SSS9S	S j5       rg)
é    )ÚchainNÚ	tree_dataÚ
tree_graphc                 óv  ^^^• U R                  5       U R                  5       S-   :w  a  [        S5      eU R                  5       (       d  [        S5      e[        R
                  " U 5      (       d  [        S5      eTT:X  a  [        R                  " S5      eUUU4S jm0 U R                  U   ETUTT" X5      0E$ )ai  Returns data in tree format that is suitable for JSON serialization
and use in JavaScript documents.

Parameters
----------
G : NetworkX graph
   G must be an oriented tree

root : node
   The root of the tree

ident : string
    Attribute name for storing NetworkX-internal graph data. `ident` must
    have a different value than `children`. The default is 'id'.

children : string
    Attribute name for storing NetworkX-internal graph data. `children`
    must have a different value than `ident`. The default is 'children'.

Returns
-------
data : dict
   A dictionary with node-link formatted data.

Raises
------
NetworkXError
    If `children` and `ident` attributes are identical.

Examples
--------
>>> from networkx.readwrite import json_graph
>>> G = nx.DiGraph([(1, 2)])
>>> data = json_graph.tree_data(G, root=1)

To serialize with json

>>> import json
>>> s = json.dumps(data)

Notes
-----
Node attributes are stored in this format but keys
for attributes must be strings if you want to serialize with JSON.

Graph and edge attributes are not stored.

See Also
--------
tree_graph, node_link_data, adjacency_data
é   zG is not a tree.zG is not directed.zG is not weakly connected.z5The values for `id` and `children` must be different.c                 óº   >• X   n[        U5      S:X  a  / $ / nU H<  n0 UR                  U   ET	U0EnT" XA5      nU(       a  XeT'   UR                  U5        M>     U$ )Nr   )ÚlenÚnodesÚappend)
ÚnÚGÚnbrsÚ	children_ÚchildÚdÚcÚadd_childrenÚchildrenÚidents
          €€€Ú_/home/mande/repo/quber/.venv/lib/python3.13/site-packages/networkx/readwrite/json_graph/tree.pyr   Útree_data.<locals>.add_childrenF   sl   ø€ Ø‰tˆÜˆt‹9˜‹>ØˆIØˆ	ÛˆEØ0�1—7‘7˜5‘>Ð0 5¨%Ñ0ˆAÙ˜UÓ&ˆAÞØ�(‘Ø×Ñ˜QÖñ ð Ðó    )Únumber_of_nodesÚnumber_of_edgesÚ	TypeErrorÚis_directedÚnxÚis_weakly_connectedÚNetworkXErrorr
   )r   Úrootr   r   r   s     ``@r   r   r      sª   ú€ ðh 	×ÑÓ˜a×/Ñ/Ó1°AÑ5Ó5ÜÐ*Ó+Ð+Ø�=‰=�?‰?ÜÐ,Ó-Ð-Ü×!Ò! !×$Ñ$ÜÐ4Ó5Ð5à�ÓÜ×ÒÐVÓWÐW÷ð Kˆa�g‰g�d‰mÐJ˜U D¨(±LÀÓ4IÑJÐJr   T)ÚgraphsÚreturns_graphc                 ó6  ^^^^	• [         R                  " 5       m	UUU	U4S jmU T   nU R                  T/ 5      nU R                  5        VVs0 s H!  u  pVUT:w  d  M  UT:w  d  M  [	        U5      U_M#     nnnT	R
                  " U40 UD6  T" X45        T	$ s  snnf )aµ  Returns graph from tree data format.

Parameters
----------
data : dict
    Tree formatted graph data

ident : string
    Attribute name for storing NetworkX-internal graph data. `ident` must
    have a different value than `children`. The default is 'id'.

children : string
    Attribute name for storing NetworkX-internal graph data. `children`
    must have a different value than `ident`. The default is 'children'.

Returns
-------
G : NetworkX DiGraph

Examples
--------
>>> from networkx.readwrite import json_graph
>>> G = nx.DiGraph([(1, 2)])
>>> data = json_graph.tree_data(G, root=1)
>>> H = json_graph.tree_graph(data)

See Also
--------
tree_data, node_link_data, adjacency_data
c                 ó4  >• U H‹  nUT   nT
R                  X5        UR                  T	/ 5      nU(       a  T" X45        UR                  5        VVs0 s H!  u  pVUT:w  d  M  UT	:w  d  M  [        U5      U_M#     nnnT
R                  " U40 UD6  M�     g s  snnf )N)Úadd_edgeÚgetÚitemsÚstrÚadd_node)Úparentr   Údatar   ÚgrandchildrenÚkÚvÚnodedatar   r   Úgraphr   s           €€€€r   r   Ú tree_graph.<locals>.add_childrenx   s‘   ø€ ÛˆDØ˜‘KˆEØ�N‰N˜6Ô)Ø ŸH™H X¨rÓ2ˆMÞÙ˜UÔ2à&*§j¡j¤lôÚ&2™d˜a°a¸5±j“	ÀQÈ(Á]“	”�A“˜’	¡lð ñ ð �NŠN˜5Ñ- HÔ-ò ùós   ÁBÁ!BÁ)B)r   ÚDiGraphr&   r'   r(   r)   )
r+   r   r   r    r   r-   r.   r/   r   r0   s
    ``     @@r   r   r   V   sŽ   û€ ô@ �JŠJ‹L€E÷
.ð 
.ð �‰;€DØ—‘˜ 2Ó&€IØ&*§j¡j¤lÔS¢l™d˜a°a¸5±j“	ÀQÈ(Á]“	”�A“˜’	¡l€HÑSØ	‡N‚N�4Ñ$˜8Ò$Ù�Ô!Ø€Lùó Ts   ÁBÁBÁ%B)Úidr   )Ú	itertoolsr   Únetworkxr   Ú__all__r   Ú_dispatchabler   © r   r   Ú<module>r9      s>   ðÝ ã à˜Ð
%€ôKKð\ ×Ò˜¨TÑ2ó2ó 3ñ2r   