def convert_node(graph, tree_node):
    """
    Add a tree node to a graph.

    Parameters
    ----------
    graph : Graph
        The graph where the node should be added.
    tree_node : Node
        The node to be added.
    
    Returns
    -------
    node_id : int or tuple
        The identifier of the added node in the graph.
        If the node is a leaf node, this is the reference index,
        otherwise this is a tuple, containing the identifier of the
        child nodes.
    distance : float
        The distance of the given node to its parent node.
    """
    if tree_node.is_leaf():
        return tree_node.index, tree_node.distance
    else:
        child_ids = []
        child_distances = []
        for child_node in tree_node.children:
            id, dist = convert_node(graph, child_node)
            child_ids.append(id)
            child_distances.append(dist)
        this_id = tuple(child_ids)
        for id, dist in zip(child_ids, child_distances):
            # Add connection to children as edge in the graph
            # Distance is added as attribute
            graph.add_edge(this_id, id, distance=dist)
        return this_id, tree_node.distance