atcoder#ABC218F. [ABC218F] Blocked Roads
[ABC218F] Blocked Roads
Score : points
Problem Statement
You are given a directed graph with vertices and edges. The vertices are numbered through , and the edges are numbered through . Edge goes from Vertex to Vertex and has a length of .
For each , find the shortest distance from Vertex to Vertex when all edges except Edge are passable, or print -1
if Vertex is unreachable from Vertex .
Constraints
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print lines.
The -th line should contain the shortest distance from Vertex to Vertex when all edges except Edge are passable, or -1
if Vertex is unreachable from Vertex .
3 3
1 2
1 3
2 3
1
2
1
4 4
1 2
2 3
2 4
3 4
-1
2
3
2
Vertex is unreachable from Vertex when all edges except Edge are passable, so the corresponding line contains -1
.
5 10
1 2
1 4
1 5
2 1
2 3
3 1
3 2
3 5
4 2
4 3
1
1
3
1
1
1
1
1
1
1
4 1
1 2
-1