Ë
    D^(h  ã                   ó^   — d dl mZ d dlZddgZd	d„Z ej                  dd¬«      d	d„«       Zy)
é    )ÚchainNÚ	tree_dataÚ
tree_graphc                 óZ  ‡‡‡— | j                  «       | j                  «       dz   k7  rt        d«      ‚| j                  «       st        d«      ‚t	        j
                  | «      st        d«      ‚‰‰k(  rt	        j                  d«      ‚ˆˆˆfd„Ši | j                  |   ¥‰|‰ ‰|| «      i¥S )a  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                 ó°   •— ||    }t        |«      dk(  rg S g }|D ]8  }i |j                  |   ¥‰	|i¥} ‰||«      }|r||‰<   |j                  |«       Œ: |S )Nr   )ÚlenÚnodesÚappend)
ÚnÚGÚnbrsÚ	children_ÚchildÚdÚcÚadd_childrenÚchildrenÚidents
          €€€ú`/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/networkx/readwrite/json_graph/tree.pyr   ztree_data.<locals>.add_childrenF   sw   ø€ Ø�‰tˆÜˆt‹9˜Š>ØˆIØˆ	Øò 	 ˆEØ0�1—7‘7˜5‘>Ð0 5¨%Ñ0ˆAÙ˜U AÓ&ˆ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ÀÀqÓ4IÑJÐJr   T)ÚgraphsÚreturns_graphc                 ó(  ‡‡‡‡	— t        j                  «       Š	ˆˆˆ	ˆfd„Š| ‰   }| j                  ‰g «      }| j                  «       D ��ci c]  \  }}|‰k7  sŒ|‰k7  sŒt	        |«      |“Œ }}} ‰	j
                  |fi |¤Ž  ‰||«       ‰	S c c}}w )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                 ó  •— |D ]�  }|‰   }‰
j                  | |«       |j                  ‰	g «      }|r	 ‰||«       |j                  «       D ��ci c]  \  }}|‰k7  sŒ|‰	k7  sŒt        |«      |“Œ }}} ‰
j                  |fi |¤Ž Œƒ y c c}}w )N)Úadd_edgeÚgetÚitemsÚstrÚadd_node)Úparentr   Údatar   ÚgrandchildrenÚkÚvÚnodedatar   r   Úgraphr   s           €€€€r   r   z tree_graph.<locals>.add_childrenx   s˜   ø€ Øò 		.ˆDØ˜‘KˆEØ�N‰N˜6 5Ô)Ø ŸH™H X¨rÓ2ˆMÙÙ˜U MÔ2à&*§j¡j£l÷Ù"˜a °a¸5³jÀQÈ(Ã]”�A“˜‘	ðˆHñ ð ˆE�N‰N˜5Ñ- HÓ-ñ		.ùós   ÁB	ÁB	Á"B	)r   ÚDiGraphr%   r&   r'   r(   )
r*   r   r   r   r   r,   r-   r.   r   r/   s
    ``     @@r   r   r   V   sŠ   û€ ô@ �J‰J‹L€E÷
.ð �‰;€DØ—‘˜ 2Ó&€IØ&*§j¡j£l×S™d˜a °a¸5³jÀQÈ(Ã]”�A“˜‘	ÐS€HÑSØ€E‡N�N�4Ñ$˜8Ò$Ù��yÔ!Ø€Lùó Ts   ÁBÁBÁB)Úidr   )Ú	itertoolsr   Únetworkxr   Ú__all__r   Ú_dispatchabler   © r   r   ú<module>r7      s@   ðÝ ã à˜Ð
%€óKKð\ €×Ñ˜¨TÔ2ò2ó 3ñ2r   