#K65767. Maximum Area of Island

    ID: 32271 Type: Default 1000ms 256MiB

Maximum Area of Island

Maximum Area of Island

You are given a 2D grid consisting of 0s and 1s where 1 represents land and 0 represents water. An island is a group of adjacent 1s connected horizontally or vertically. Your task is to compute the maximum area (i.e., the number of cells) covered by an island in the grid.

If there is no island, the maximum area is 0.

Note: Two cells are considered adjacent if they share a side. Diagonal connections do not count. The area of an island is defined as the total number of 1s that are connected.

The problem can also be expressed mathematically as finding the maximum value of \(A\), where for each island \(I\) in the grid, its area \(A(I)\) is given by:

[ A(I) = \sum_{(i,j) \in I} 1 ]

Your solution should be implemented using depth-first search (DFS) or a similar technique to traverse the grid.

inputFormat

The input is read from standard input (stdin) and has the following format:

r c
row1
row2
... 
row_r

Here, r and c are two integers representing the number of rows and columns in the grid, respectively. Each of the following r lines contains c space-separated integers (either 0 or 1) which represent the grid itself.

Note: In case r or c is 0, then the grid is empty, and the maximum area is 0.

outputFormat

Output a single integer to standard output (stdout) representing the maximum area of an island in the grid.

## sample
8 13
0 0 1 0 0 0 0 1 0 0 0 0 0
0 0 0 0 0 0 0 1 1 1 0 0 0
0 1 1 0 1 0 0 0 0 0 0 0 0
0 1 0 0 1 1 0 0 1 0 1 0 0
0 1 0 0 1 1 0 0 1 1 1 0 0
0 0 0 0 0 0 0 0 0 0 1 0 0
0 0 0 0 0 0 0 1 1 1 0 0 0
0 0 0 0 0 0 0 1 1 0 0 0 0
6