Олимпиадный тренинг

Задача 27209. Floyd


Задача

Темы:
Given a directed graph, the edges of which are assigned some non-negative weights (lengths). Find the length of the shortest path from vertex s to vertex t.
 
Input
The first line contains three numbers: the number of vertices in the graph N ≤50, the numbers of vertices s and t. Next comes the adjacency matrix of the graph, that is, N rows, each of which contains N numbers. The j-th number in the i-th row of the adjacency matrix specifies the length of the edge leading from the i-th vertex to the j-th one. Lengths can take any value from 0 to 1000000, the number -1 means that there is no corresponding edge. It is guaranteed that there are zeros on the main diagonal of the matrix.
 
Output
Print one number – minimum path length. If the path does not exist, print -1.

Enter Output
3 1 2
0 -1 3
701
22150
218