using
System;
public
class
GFG{
static
bool
uniquepath(
int
[,]matrix,
int
curr_x,
int
curr_y,
int
dest_x,
int
dest_y,
bool
[,] visited)
{
if
(curr_x == dest_x && curr_y == dest_y)
return
true
;
if
(!(curr_x >= 0 && curr_x < matrix.GetLength(0) &&
curr_y >= 0 && curr_y < matrix.GetLength(1)))
return
false
;
if
(visited[curr_x,curr_y] ==
true
)
return
false
;
visited[curr_x,curr_y] =
true
;
if
(matrix[curr_x,curr_y] == 1)
return
uniquepath(matrix, curr_x, curr_y + 1,
dest_x, dest_y, visited);
else
if
(matrix[curr_x,curr_y] == 2)
return
uniquepath(matrix, curr_x, curr_y - 1,
dest_x, dest_y, visited);
else
if
(matrix[curr_x,curr_y] == 3)
return
uniquepath(matrix, curr_x + 1, curr_y,
dest_x, dest_y, visited);
else
if
(matrix[curr_x,curr_y] == 4)
return
uniquepath(matrix, curr_x - 1, curr_y,
dest_x, dest_y, visited);
return
false
;
}
public
static
void
Main(String[] args)
{
int
[,] matrix = { { 3, 2, 2, 2 },
{ 3, 4, 2, 3 },
{ 1, 3, 4, 4 },
{ 2, 1, 1, 2 },
{ 4, 4, 1, 2 } };
int
start_x = 0, start_y = 3;
int
dest_x = 3, dest_y = 1;
int
n = matrix.GetLength(0);
int
m = matrix.GetLength(1);
bool
[,] visited =
new
bool
[n,m];
if
(uniquepath(matrix, start_x, start_y,
dest_x, dest_y, visited))
Console.Write(
"Yes"
);
else
Console.Write(
"No"
);
}
}