Write a function to calculate the minimum distance in a graph.
Use the signature def shortest_distance(graph, source, target):, where graph is an adjacency list and each edge is represented as [neighbor, weight]; return the minimum total weight from source to target, or -1 if unreachable. Edge weights are nonnegative, and examples include directed graphs, cycles, and multiple routes.
Constraints: 1 <= len(graph) <= 5000, 0 <= source, target < len(graph), and every neighbor is a valid node index.
def shortest_distance(graph, source, target):