#C1273. Largest Connected Region in a Binary Matrix
Largest Connected Region in a Binary Matrix
Largest Connected Region in a Binary Matrix
You are given an \( n \times n \) binary matrix, where each element is either 0 or 1. A region is defined as a group of adjacent 1's, where adjacent means cells sharing a side (up, down, left, or right). Your task is to determine the size of the largest connected region of 1's in the matrix.
Note: Diagonally adjacent cells are not considered connected.
Example:
Input: 4 1 1 0 0 1 0 1 0 0 0 1 1 1 0 0 0</p>Output: 3
In the above example, the largest connected region has size 3.
inputFormat
The first line of input contains an integer \( n \) denoting the size of the matrix. The following \( n \) lines each contain \( n \) space-separated integers (either 0 or 1) representing the rows of the matrix.
outputFormat
Output a single integer indicating the size of the largest connected region of 1's.
## sample4
1 1 0 0
1 0 1 0
0 0 1 1
1 0 0 0
3
</p>