HomeVolumesContestsSectionsForumsUsersPrintHelpAbout

Sections > Unsorted > problem:


Bfs

Section problems

• Maximum
• Name-Surname
• Decimal to binary
• Heap
• Herons
• Leap Year
• Perfect numbers
• Rectangle
• Bfs
• Chess
• Big Dance
• Binary to decimal
• Circle
• City Tour
• Dijkstra
• Fibonacci Series
• Find the biggest 2

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 all others in directed graph.

Input

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

Line 2..N+1: Adjacency matrix.

Output

Write N integers - distances to all vertices, if there isn't any path write -1.

Example

stdin stdout

4 4
0 1 1 1
0 0 1 0
0 0 0 0
1 1 0 0

1 1 2 0

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

www.contester.ru