<｜begin▁of▁sentence｜>### Instruction:
Given a directed graph with weights, including possible negative weights, find the shortest path lengths and predecessors for paths starting from a given source node using the goldberg_radzik algorithm from NetworkX. The graph has a path graph structure with additional edges creating potential negative cycles. How can you handle the detection of negative cycles using this function?
### Response:
import networkx as nx

# Create a weighted graph
G = nx.path_graph(5, create_using=nx.DiGraph())
G.add_edge(1, 2, weight=-1)
G.add_edge(2, 3, weight=4)
G.add_edge(3, 4, weight=-1)
G.add_edge(4, 1, weight=2)

# Use the goldberg_radzik function to find shortest paths
try:
    pred, dist = nx.goldberg_radzik(G, 0)
    print('Predecessors:', pred)
    print('Distances:', dist)
except nx.NetworkXUnbounded as e:
    print('Error:', e)
<|EOT|>
