<｜begin▁of▁sentence｜>### Instruction:
Given a weighted directed graph with edges [(0, 1, 3), (1, 2, -2), (2, 3, 5), (3, 0, 1)], how can you use the Goldberg-Radzik algorithm to compute the shortest path lengths and predecessors from source node 0, handling potential negative cycles?
### Response:
import networkx as nx

# Create a weighted digraph
G = nx.DiGraph()
G.add_weighted_edges_from([(0, 1, 3), (1, 2, -2), (2, 3, 5), (3, 0, 1)])

# Compute shortest path lengths and predecessors
# using the Goldberg-Radzik algorithm
try:
    pred, dist = nx.goldberg_radzik(G, 0)
    print('Predecessors:', pred)
    print('Distances:', dist)
except nx.NetworkXUnbounded as e:
    print(e)
<|EOT|>
