using
System;
class
GFG
{
static
int
INF=99999;
static
int
findMinimumSteps(
int
[,]mat,
int
x,
int
y,
int
n)
{
int
i, j, k;
int
[,] dist=
new
int
[n,n];
for
(i = 0; i < n; i++) {
for
(j = 0; j < n; j++) {
if
(mat[i,j] == 0)
dist[i,j] = INF;
else
dist[i,j] = 1;
if
(i == j)
dist[i,j] = 1;
}
}
for
(k = 0; k < n; k++) {
for
(i = 0; i < n; i++) {
for
(j = 0; j < n; j++) {
if
(dist[i,k] + dist[k,j] < dist[i,j])
dist[i,j] = dist[i,k] + dist[k,j];
}
}
}
if
(dist[x,y] < INF)
return
dist[x,y];
else
return
-1;
}
public
static
void
Main()
{
int
[,] mat = { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 1, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
{ 0, 0, 0, 1, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
{ 0, 1, 0, 0, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 } };
int
x = 2, y = 3;
int
size = mat.GetLength(0) ;
Console.WriteLine( findMinimumSteps(mat, x, y, size));
}
}