Dijkstra#657

Dijkstra

2 seconds
128 megabytes
Medium (≈1350)

The directed weighted graph is given. Find the shortest distance from one vertex to another.

Input

The first line contains three integers and f~(1 \le n \le 2000; 1 \le s, f \le n), 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

Example 1

Loading
Loading