<｜begin▁of▁sentence｜>### Instruction:
Given a directed graph with weighted edges [(0, 1, 2), (1, 2, 1), (0, 2, 4), (2, 3, 1)], can you find the shortest paths and their lengths from each node to all other reachable nodes using NetworkX?
### Response:
import networkx as nx

# Create a weighted graph
G = nx.DiGraph()
G.add_weighted_edges_from([(0, 1, 2), (1, 2, 1), (0, 2, 4), (2, 3, 1)])

# Compute shortest paths and lengths
for source, (length_dict, path_dict) in nx.all_pairs_dijkstra(G):
    print(f'Shortest paths from node {source}:')
    for target in path_dict:
        print(f' - to node {target}: {path_dict[target]}, length: {length_dict[target]}')
<|EOT|>
