using
System;
using
System.Collections;
using
System.Collections.Generic;
class
GFG {
class
pair {
public
int
first, second;
public
pair(
int
first,
int
second)
{
this
.first = first;
this
.second = second;
}
}
static
int
BFS(
int
[, ] matrix,
int
row,
int
col)
{
int
area = 0;
Queue<pair> Q =
new
Queue<pair>();
Q.Enqueue(
new
pair(row, col));
while
(Q.Count != 0) {
pair it = Q.Peek();
Q.Dequeue();
int
r = it.first, c = it.second;
if
(r < 0 || c < 0 || r > 4 || c > 4)
continue
;
if
(matrix[r, c] == 0)
continue
;
if
(matrix[r, c] == 1) {
matrix[r, c] = 0;
area++;
}
Q.Enqueue(
new
pair(r + 1, c));
Q.Enqueue(
new
pair(r - 1, c));
Q.Enqueue(
new
pair(r, c + 1));
Q.Enqueue(
new
pair(r, c - 1));
}
return
area;
}
static
void
sizeOfConnections(
int
[, ] matrix)
{
ArrayList result =
new
ArrayList();
for
(
int
row = 0; row < 5; ++row) {
for
(
int
col = 0; col < 5; ++col) {
if
(matrix[row, col] == 1) {
int
area = BFS(matrix, row, col);
result.Add(area);
}
}
}
foreach
(
int
val
in
result) Console.Write(val +
" "
);
}
public
static
void
Main(
string
[] args)
{
int
[, ] matrix = { { 1, 1, 0, 0, 0 },
{ 1, 1, 0, 1, 1 },
{ 1, 0, 0, 1, 1 },
{ 1, 0, 0, 0, 0 },
{ 0, 0, 1, 1, 1 } };
sizeOfConnections(matrix);
}
}