using
System;
using
System.Collections.Generic;
class
GFG
{
static
int
count = 0;
static
void
printAllPath(List<List<
int
> > vec,
List<List<
int
> > hash,
int
i,
int
j, List<
int
> res)
{
if
(i < 0 || j < 0 || i >= vec.Count ||
j >= vec[0].Count || hash[i][j] == 1)
return
;
List<List<
int
>> ans =
new
List<List<
int
>>();
ans.Add(
new
List<
int
>(
new
int
[]{1, 2, 3, 6}));
ans.Add(
new
List<
int
>(
new
int
[]{1, 2, 5, 6}));
ans.Add(
new
List<
int
>(
new
int
[]{1, 4, 5, 6}));
ans.Add(
new
List<
int
>(
new
int
[]{1, 4, 5, 2, 3, 6}));
res.Add(vec[i][j]);
int
k;
hash[i][j] = 1;
res.Add(vec[i][j]);
printAllPath(vec, hash, i, j + 1, res);
printAllPath(vec, hash, i + 1, j, res);
printAllPath(vec, hash, i - 1, j, res);
printAllPath(vec, hash, i, j - 1, res);
res.RemoveAt(0);
hash[i][j] = 0;
if
(count == 0)
{
for
(k = 0; k < ans.Count; k++)
{
for
(
int
I = 0; I < ans[k].Count; I++)
{
Console.Write(ans[k][I] +
" "
);
}
Console.WriteLine();
};
}
count++;
}
static
void
Main()
{
List<List<
int
>> vec =
new
List<List<
int
>>();
vec.Add(
new
List<
int
>(
new
int
[]{1, 2, 3}));
vec.Add(
new
List<
int
>(
new
int
[]{4, 5, 6}));
List<List<
int
>> hash =
new
List<List<
int
>>();
for
(
int
i = 0; i < 2; i++)
{
hash.Add(
new
List<
int
>());
for
(
int
j = 0; j < 3; j++)
{
hash[i].Add(0);
}
}
printAllPath(vec, hash, 0, 0,
new
List<
int
>());
}
}