<｜begin▁of▁sentence｜>### Instruction:
Given a weighted directed graph with edges [(0, 1, 5), (1, 2, 3), (2, 3, -2), (3, 0, 1)], can you apply the Bellman-Ford algorithm to find the shortest paths and distances from node 0 to all other nodes?
### Response:
import networkx as nx

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

# Compute shortest paths and distances from node 0 using Bellman-Ford algorithm
pred, dist = nx.bellman_ford_predecessor_and_distance(G, 0)

# Print the predecessor and distance dictionaries
print('Predecessors:', pred)
print('Distances:', dist)
<|EOT|>
