Solve a Dijkstra-based graph problem at a medium to hard level.
Implement shortest_path(n, edges, source, target). The directed graph has nodes 0 through n - 1; each edge is [from, to, weight]. Return [distance, path], where path lists nodes from source to target. Return [-1, []] when the target is unreachable.
All weights are non-negative. If multiple shortest paths exist, return the path produced by processing edges in their given order.
def shortest_path(n, edges, source, target):