#P3371. 【模板】单源最短路径(弱化版)
【模板】单源最短路径(弱化版)
Description
As stated, given a directed graph, output the shortest path length from a specified vertex to every vertex.
Input Format
The first line contains three integers , denoting the number of vertices, the number of directed edges, and the index of the source vertex.
Each of the next lines contains three integers , denoting a directed edge with length .
Output Format
Output integers on one line. The -th integer is the shortest path distance from to vertex . If a vertex is unreachable, output .
4 6 1
1 2 2
2 3 2
2 4 1
1 3 5
3 4 3
1 4 4
0 2 4 3
Hint
-
Constraints
For of the testdata: , ;
For of the testdata: , ;
For of the testdata: , ;
For of the testdata: , , , , ; the testdata is guaranteed to be random. -
Update 2022/07/29: There may be multiple edges between two vertices. Please take note.
-
For the full testdata, please refer to P4779. Note that its constraints differ slightly from this problem.
Sample note:

In the image, the text positions for "1 to 3" and "1 to 4" are swapped.
Translated by ChatGPT 5
京公网安备 11011102002149号