#abc218f. [abc218_f]Blocked Roads
[abc218_f]Blocked Roads
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 .
Sample Input 1
3 3
1 2
1 3
2 3
Sample Output 1
1
2
1
Sample Input 2
4 4
1 2
2 3
2 4
3 4
Sample Output 2
-1
2
3
2
Vertex is unreachable from Vertex when all edges except Edge are passable, so the corresponding line contains -1
.
Sample Input 3
5 10
1 2
1 4
1 5
2 1
2 3
3 1
3 2
3 5
4 2
4 3
Sample Output 3
1
1
3
1
1
1
1
1
1
1
Sample Input 4
4 1
1 2
Sample Output 4
-1