HomeVolumesContestsSectionsForumsUsersPrintHelpAbout

Sections > Unsorted > problem:


Dijkstra

Section problems

• Circle
• Herons
• Profits
• Maximum
• Tickets
• Flowers
• Istanbul
• T-shirts
• Dijkstra
• Workshop
• Big Dance
• Molecules
• Leap Year
• Factorial
• Rectangle
• City Tour
• Buying hay

Feedback

If you notice incorrect translations in Contester, please let author know.

Time limit 1000/1000/4000/4000 ms. Memory limit 65000/65000/65000/65000 Kb.

Problem description

Find the shortest path from vertex S to F in directed weighted graph.

Input

Line 1: Three integers: N - number of vertices, S - starting vertex, F - destination vertex (1 ≤ S, F ≤ N ≤ 100).

Line 2..N+1: Adjacency matrix, where -1 - means no edge, a[i][j] = 0 when i=j, all other positive integers ≤ 1000 are weights of edges.

Output

Write distance from S to F or -1 if there is no path.

Example

stdin stdout

3 1 2
0 -1 2
3 0 -1
-1 4 0

6

Для отправки решений необходимо выполнить вход.

www.contester.ru