human
Complete this python program:
def goldberg_radzik(G, source, weight='weight'):
assistant
#Here is the Python code you requested.

    """Compute shortest path lengths and predecessors on shortest paths
    in weighted graphs.
    The algorithm has a running time of O(mn) where n is the number of
    nodes and m is the number of edges.  It is slower than Dijkstra but
    can handle negative edge weights.
    Parameters
    G : NetworkX graph
    The algorithm works for all types of graphs, including directed
    graphs and multigraphs.
    source: node label
    Starting node for path
    weight : string or function
    If this is a string, then edge weights will be accessed via the
    edge attribute with this key (that is, the weight of the edge
    joining `u` to `v` will be ``G.edge[u][v][weight]``). If no
    such edge attribute exists, the weight of the edge is assumed to
    be one.
    If this is a function, the weight of an edge is the value
    returned by the function. The function must accept exactly three
    positional arguments: the two endpoints of an edge and the
    dictionary of edge attributes for that edge. The function must
    return a number.
    Returns
    pred, dist : dictionaries
    Returns two dictionaries keyed by node to predecessor in the
    path and to the distance from the source respectively.
    Raises
    NetworkXUnbounded
    If the (di)graph contains a negative cost (di)cycle, the
    algorithm raises an exception to indicate the presence of the
    negative cost (di)cycle.  Note: any negative weight edge in an
    undirected graph is a negative cost cycle.
    Examples
    >>> import networkx as nx
    >>> G = nx.path_graph(5, create_using = nx.DiGraph())
    >>> pred, dist = nx.goldberg_radzik(G, 0)
    >>> sorted(pred.items())
    [(0, None), (1, 0), (2, 1), (3, 2), (4, 3)]
    >>> sorted(dist.items())
    [(0, 0), (1, 1), (2, 2), (3, 3), (4, 4)]
    >>> from nose.tools import assert_raises
    >>> G = nx.cycle_graph(5, create_using = nx.DiGraph())
    >>> G[1][2][\weight\] = -7
    >>> assert_raises(nx.NetworkXUnbounded, nx.goldberg_radzik, G, 0)
    Notes
    Edge weight attributes must be..."""
    if (source not in G):
        raise nx.NodeNotFound(('Node    %s    is    not    found    in    the    graph' % source))
    weight = _weight_function(G, weight)
    if any(((weight(u, v, d) < 0) for (u, v, d) in G.selfloop_edges(data=True))):
        raise nx.NetworkXUnbounded('Negative    cost    cycle    detected.')
    if (len(G) == 1):
        return ({source: None}, {source: 0})
    if G.is_directed():
        G_succ = G.succ
    else:
        G_succ = G.adj
    inf = float('inf')
    d = dict(((u, inf) for u in G))
    d[source] = 0
    pred = {source: None}
    def topo_sort(relabeled):
        'Topologically    sort    nodes    relabeled    in    the    previous    round    and    detect\n                                negative    cycles.\n                                '
        to_scan = []
        neg_count = {}
        for u in relabeled:
            if (u in neg_count):
                continue
            d_u = d[u]
            if all((((d_u + weight(u, v, e)) >= d[v]) for (v, e) in G_succ[u].items())):
                continue
            stack = [(u, iter(G_succ[u].items()))]
            in_stack = set([u])
            neg_count[u] = 0
            while stack:
                (u, it) = stack[(-1)]
                try:
                    (v, e) = next(it)
                except StopIteration:
                    to_scan.append(u)
                    stack.pop()
                    in_stack.remove(u)
                    continue
                t = (d[u] + weight(u, v, e))
                d_v = d[v]
                if (t <= d_v):
                    is_neg = (t < d_v)
                    d[v] = t
                    pred[v] = u
                    if (v not in neg_count):
                        neg_count[v] = (neg_count[u] + int(is_neg))
                        stack.append((v, iter(G_succ[v].items())))
                        in_stack.add(v)
                    elif ((v in in_stack) and ((neg_count[u] + int(is_neg)) > neg_count[v])):
                        raise...