#C6527. Maximum Area of Island

    ID: 50297 Type: Default 1000ms 256MiB

Maximum Area of Island

Maximum Area of Island

Given an m×nm \times n grid of characters where each cell is either '1' (land) or '0' (water), an island is a group of connected '1's (cells connected horizontally or vertically). Your task is to compute the area (number of cells) of the largest island in the grid. If there is no island, return 0.

Formally, if we denote the grid by GG, an island is a connected component of cells where G[i][j]=1G[i][j] = 1. The area is simply the count of cells in that component. Use Depth-First Search (DFS) or Breadth-First Search (BFS) to solve this problem.

inputFormat

The first line of input contains two space-separated integers mm and nn, representing the number of rows and columns respectively. Each of the next mm lines contains nn space-separated integers (either 0 or 1), representing the grid.

outputFormat

Output a single integer, which is the maximum area of an island found in the grid.## sample

4 5
1 1 0 0 0
1 1 0 0 0
0 0 1 0 0
0 0 0 1 1
4