<｜begin▁of▁sentence｜>### Instruction:
Given a weighted directed graph with edge set [(0, 1, 3), (1, 2, -2), (2, 3, 5), (3, 0, 1)], can you compute the shortest path lengths and predecessors from node 0 using the Goldberg-Radzik algorithm provided by NetworkX? What would be the result if the graph contains a negative weight cycle?
### Response:
import networkx as nx

# Create a directed graph with weights
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
# on weighted graph using Goldberg-Radzik algorithm
try:
  pred, dist = nx.goldberg_radzik(G, 0)
  print('Predecessors:', sorted(pred.items()))
  print('Distances:', sorted(dist.items()))
except nx.NetworkXUnbounded:
  print('Graph contains a negative weight cycle')
<|EOT|>
