human
Solve the following python programming problem given the following code:
@not_implemented_for('undirected')
def recursive_simple_cycles(G):
assistant
#Here is the Python code you requested.

    """Find simple cycles (elementary circuits) of a directed graph.
    A `simple cycle`, or `elementary circuit`, is a closed path where
    no node appears twice. Two elementary circuits are distinct if they
    are not cyclic permutations of each other.
    This version uses a recursive algorithm to build a list of cycles.
    You should probably use the iterator version called simple_cycles().
    Warning: This recursive version uses lots of RAM!
    Parameters
    G : NetworkX DiGraph
    A directed graph
    Returns
    A list of cycles, where each cycle is represented by a list of nodes
    along the cycle.
    Example:
    >>> edges = [(0, 0), (0, 1), (0, 2), (1, 2), (2, 0), (2, 1), (2, 2)]
    >>> G = nx.DiGraph(edges)
    >>> nx.recursive_simple_cycles(G)
    [[0], [0, 1, 2], [0, 2], [1, 2], [2]]
    See Also
    cycle_basis (for undirected graphs)
    Notes
    The implementation follows pp. 79-80 in [1]_.
    The time complexity is `O((n+e)(c+1))` for `n` nodes, `e` edges and `c`
    elementary circuits.
    References
    .. [1] Finding all the elementary circuits of a directed graph.
    D. B. Johnson, SIAM Journal on Computing 4, no. 1, 77-84, 1975.
    http://dx.doi.org/10.1137/0204007
    See Also
    simple_cycles, cycle_basis
    """
    def _unblock(thisnode):
        'Recursively    unblock    and    remove    nodes    from    B[thisnode].'
        if blocked[thisnode]:
            blocked[thisnode] = False
            while B[thisnode]:
                _unblock(B[thisnode].pop())
    def circuit(thisnode, startnode, component):
        closed = False
        path.append(thisnode)
        blocked[thisnode] = True
        for nextnode in component[thisnode]:
            if (nextnode == startnode):
                result.append(path[:])
                closed = True
            elif (not blocked[nextnode]):
                if circuit(nextnode, startnode, component):
                    closed = True
        if closed:
            _unblock(thisnode)
        else:
            for nextnode in component[thisnode]:
                if (thisnode not in B[nextnode]):
                    B[nextnode].append(thisnode)
        path.pop()
        return closed
    path = []
    blocked = defaultdict(bool)
    B = defaultdict(list)
    result = []
    ordering = dict(zip(G, range(len(G))))
    for s in ordering:
        subgraph = G.subgraph((node for node in G if (ordering[node] >= ordering[s])))
        strongcomp = nx.strongly_connected_components(subgraph)
        mincomp = min(strongcomp, key=(lambda ns: min((ordering[n] for n in ns))))
        component = G.subgraph(mincomp)
        if component:
            startnode = min(component, key=ordering.__getitem__)
            for node in component:
                blocked[node] = False
                B[node][:] = []
            dummy = circuit(startnode, startnode, component)
    return result