HomeVolumesContestsSectionsForumsUsersPrintHelpAbout

Sections > Unsorted > problem:


Bfs

Section problems

• Meat store
• Bit Decoder
• Knights of the Rook
• Coins
• Primes
• Providers
• A+B
• GCF
• Bfs
• Sign
• Heap
• Timer
• Chess
• Circle
• Herons
• Profits
• Maximum

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