The shortest distance
Execution time limit is 2 seconds
Runtime memory usage limit is 128 megabytes
The directed graph is given. Find the shortest distance from the vertex to other vertices of the graph.
Input
The first line contains two integers and — the number of vertices in a graph and the starting vertex. Each of the next lines contains numbers — the adjacency matrix of the graph: the -th line and -th column contains "", if the vertices and are connected with the edge, and "", if there is no edge between them. The main diagonal contains zeroes.
Output
Print the numbers , where is if there is no path from to , or the minimal distance from to otherwise.
Examples
Input #1
Answer #1
Submissions 7K
Acceptance rate 57%