#abc218f. F - Blocked Roads
F - Blocked Roads
Score : points
问题描述
你得到一个有向图,包含 个顶点和 条边。顶点编号从 到 ,边的编号从 到 。第 条边 从顶点 指向顶点 ,且边长为 。
对于每个 ,在除第 条边之外的所有边均可通行的情况下,找出从顶点 到顶点 的最短距离。若此时顶点 从顶点 不可达,则输出 -1
。
以上为通义千问 qwen-max 翻译,仅供参考。
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
update @ 2024/3/10 09:39:19