13190 - The Shortest Way Back Home   

Description

 

Input

First line, you will get the row and column of the matrix.

1 <= R <= 105, 1 <= C <= 105

Second line, you will get the start position of the matrix.

0 <= X < 105, 0 <= Y < 105

Third line, you will get a 2D matrix, for each element N in the matrix:

-1 <= N <= 9

Output

The output should be the distance from root to leaf of the shortest path.

(Remember to print out "\n" after the answer)

Sample Input  Download

Sample Output  Download

Tags




Discuss