HomeVolumesContestsSectionsForumsUsersPrintHelpAbout

Volumes > C. T. 2011 > problem:


Bfs

Volume problems

• A to the power of B
• T-shirts
• GCF
• Maximum Sum
• Making Change
• Best Grass
• Heap
• Bfs
• Chess
• Big Dance
• Binary transformations
• Dijkstra
• Tickets
• Flowers
• Bookshelf
• Coin Game

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