human
Solve the following python programming problem given the following code:
@not_implemented_for('directed')
@not_implemented_for('multigraph')
def chain_decomposition(G, root=None):
assistant
#Here is the Python program you requested.

    """Return the chain decomposition of a graph.
    The *chain decomposition* of a graph with respect a depth-first
    search tree is a set of cycles or paths derived from the set of
    fundamental cycles of the tree in the following manner. Consider
    each fundamental cycle with respect to the given tree, represented
    as a list of edges beginning with the nontree edge oriented away
    from the root of the tree. For each fundamental cycle, if it
    overlaps with any previous fundamental cycle, just take the initial
    non-overlapping segment, which is a path instead of a cycle. Each
    cycle or path is called a *chain*. For more information, see [1]_.
    Parameters
    G : undirected graph
    root : node (optional)
    A node in the graph `G`. If specified, only the chain
    decomposition for the connected component containing this node
    will be returned. This node indicates the root of the depth-first
    search tree.
    Yields
    chain : list
    A list of edges representing a chain. There is no guarantee on
    the orientation of the edges in each chain (for example, if a
    chain includes the edge joining nodes 1 and 2, the chain may
    include either (1, 2) or (2, 1)).
    Raises
    NodeNotFound
    If `root` is not in the graph `G`.
    Notes
    The worst-case running time of this implementation is linear in the
    number of nodes and number of edges [1]_.
    References
    .. [1] Jens M. Schmidt (2013). "A simple test on 2-vertex-
    and 2-edge-connectivity." *Information Processing Letters*,
    113, 241â244. Elsevier. <http://dx.doi.org/10.1016/j.ipl.2013.01.016>
    """
    def _dfs_cycle_forest(G, root=None):
        'Builds    a    directed    graph    composed    of    cycles    from    the    given    graph.\n\n                                `G`    is    an    undirected    simple    graph.    `root`    is    a    node    in    the    graph\n                                from    which    the    depth-first    search    is    started.\n\n                                This    function    returns    both    the    depth-first    search    cycle    graph\n                                (as    a    :class:`~networkx.DiGraph`)    and    the    list    of    nodes    in\n                                depth-first    preorder.    The    depth-first    search    cycle    graph    is    a\n                                directed    graph    whose    edges    are    the    edges    of    `G`    oriented    toward\n                                the    root    if    the    edge    is    a    tree    edge    and    away    from    the    root    if\n                                the    edge    is    a    non-tree    edge.    If    `root`    is    not    specified,    this\n                                performs    a    depth-first    search    on    each    connected    component    of    `G`\n                                and    returns    a    directed    forest    instead.\n\n                                If    `root`    is    not    in    the    graph,    this    raises    :exc:`KeyError`.\n\n                                '
        H = nx.DiGraph()
        nodes = []
        for (u, v, d) in nx.dfs_labeled_edges(G, source=root):
            if (d == 'forward'):
                if (u == v):
                    H.add_node(v, parent=None)
                    nodes.append(v)
                else:
                    H.add_node(v, parent=u)
                    H.add_edge(v, u, nontree=False)
                    nodes.append(v)
            elif ((d == 'nontree') and (v not in H[u])):
                H.add_edge(v, u, nontree=True)
            else:
               ...