Dijkstra
Very easy
Execution time limit is 2 seconds
Runtime memory usage limit is 128 megabytes
The directed weighted graph is given. Find the shortest distance from one vertex to another.
Input
The first line contains three integers and , where is the number of graph vertices, is the initial vertex, and is the final vertex. Each of the next lines contains integers — the matrix of weights of the graph, where means the lack of edge between the vertices, and any nonnegative integer — the weight of the existing edge. The main diagonal of the matrix contains zeroes.
Output
Print the shortest distance from to or if the path does not exist.
Examples
Input #1
Answer #1
Submissions 7K
Acceptance rate 45%