All-Pairs Shortest Paths
A directed graph has nodes and weighted edges. Answer queries: the shortest distance from to , or -1. With so few nodes, Floyd–Warshall () precomputes every answer.
Input
and , lines u v w (directed, there may be repeats), , then lines a b.
Output
One answer per line.
Constraints
,
Sample 1
Input
3 3 1 2 4 2 3 1 1 3 10 3 1 3 3 1 2 2
Output
5 -1 0