using
System;
using
System.Collections.Generic;
class
GFG
{
static
bool
searchForRectangle(
int
rows,
int
cols,
int
[,] mat)
{
if
(rows < 2 || cols < 2)
{
return
false
;
}
int
num_of_keys;
Dictionary<
int
, List<
int
>> adjsList =
new
Dictionary<
int
, List<
int
>>();
if
(rows >= cols)
{
num_of_keys = rows;
for
(
int
i = 0; i < rows; i++)
{
for
(
int
j = 0; j < cols; j++)
{
if
(mat[i, j] == 1)
{
if
(!adjsList.ContainsKey(i))
adjsList[i] =
new
List<
int
>();
adjsList[i].Add(j);
}
}
}
}
else
{
num_of_keys = cols;
for
(
int
i = 0; i < rows; i++)
{
for
(
int
j = 0; j < cols; j++)
{
if
(mat[i, j] == 1)
{
if
(!adjsList.ContainsKey(i))
adjsList[i] =
new
List<
int
>();
adjsList[i].Add(j);
}
}
}
}
Dictionary<Tuple<
int
,
int
>,
int
> pairs =
new
Dictionary<Tuple<
int
,
int
>,
int
>();
for
(
int
i = 0; i < num_of_keys; i++)
{
List<
int
> values = adjsList[i];
int
size = values.Count;
for
(
int
j = 0; j < size - 1; j++)
{
for
(
int
k = j + 1; k < size; k++)
{
var
temp = Tuple.Create(values[j],
values[k]);
if
(!pairs.ContainsKey(temp))
{
return
true
;
}
else
{
pairs[temp] = i;
}
}
}
}
return
false
;
}
public
static
void
Main(
string
[] args)
{
int
[, ] mat = { { 1, 0, 0, 1, 0 },
{ 0, 1, 1, 1, 1 },
{ 0, 0, 0, 1, 0 },
{ 1, 1, 1, 1, 0 } };
if
(searchForRectangle(4, 5, mat))
Console.WriteLine(
"Yes"
);
else
Console.WriteLine(
"No"
);
}
}