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

Сборники > C. T. 2011 > задача:


Dijkstra

Задачи сборника

• Chess
• Profits
• Tickets
• Flowers
• Triangle
• Istanbul
• Brackets
• T-shirts
• Dijkstra
• Big Dance
• Bookshelf
• Coin Game
• Butterfly
• Word power
• Buying hay
• Best Grass
• Cow PinBall

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

Если у вас есть предложения или пожелания по работе 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