ГлавнаяСборникиТурнирыРазделыФорумыУчастникиПечатьПомощьО системе

Разделы > Неотсортированные > задача:


Dijkstra

Задачи раздела

• Perfect numbers
• Rectangle
• Bfs
• Chess
• Big Dance
• Binary to decimal
• Circle
• City Tour
• Dijkstra
• Fibonacci Series
• Find the biggest 2
• Find the biggest 3
• Sign
• Timer
• Tickets
• find the numbers
• Flowers

Обратная связь

Если у вас есть предложения или пожелания по работе Contester, посетите форум сайта www.contester.ru.

Лимит времени 1000/1000/4000/4000 мс. Лимит памяти 65000/65000/65000/65000 Кб.

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