


1. Left - (i, j-1)
2. Right - (i, j+1)
3. Up - (i-1, j)
4. Down - (i+1, j)
The first line of input contains two integer values, 'N' and 'M', separated by a single space. They represent the 'rows' and 'columns' respectively, for the two-dimensional array/list.
The second line onwards, the next 'N' lines or rows represent the i-th row values.
Each of the ith row constitutes 'M' column values separated by a single space.
The next and the final line contains two single space separated Integers 'X' and 'Y' where 'X' is the row number and 'Y' is the column number of the destination cell.
Print the minimum cost required to reach the destination (X, Y) from (0, 0).
If it is impossible to reach the destination, print -1.
1. You are not required to print the output explicitly, it has already been taken care of. Just implement the given function.
2. 'X' and 'Y' are 0-based indexing.
3. matrix[0][0] will always be 1.
1 <= N <= 10^3
1 <= M <= 10^3
0 <= matrix[i][j] <= 1
0 <= X < N
0 <= Y < M
where 'N' represents the number of rows, 'M' represents the number of columns, 'matrix[i][j]' represents the elements of the matrix, and 'X' and 'Y' represents the coordinates of the destination point.
Time Limit: 1 sec.
Maintain a visited array and try to explore all the possibilities with the help of backtracking.
We will use Breadth-First Search with Priority Queue to solve the problem (Similar to Dijkstra’s Algorithm).
To make our operations easy, we create a new class called Cell, which stores the cost to reach that cell, the x coordinate and y coordinate of a particular cell, in that order.
We will use Breadth-First Search with deque to solve the problem (This technique is called 0-1 BFS and it is used when we can only have 0 or 1 as our cost from one node to another)
To make our operations easy, we create a new class called Cell, which stores the cost to reach that cell, the x coordinate and y coordinate of a particular cell, in that order.