#C8655. Largest Island Size

    ID: 52661 Type: Default 1000ms 256MiB

Largest Island Size

Largest Island Size

You are given a grid with n rows and m columns. Each cell contains either 'L' representing land or 'W' representing water. Two land cells are considered connected if they are adjacent horizontally or vertically.

Your task is to find the size of the largest island (i.e. the maximum number of connected 'L' cells) in the grid. If there is no land, the answer should be 0.

Note: An island is defined as a maximal group of connected land cells. The connectivity is defined in the four directions (up, down, left, right). The problem may be modeled using a depth-first search (DFS) or breadth-first search (BFS) over the grid.

The solution may involve using recursive DFS to traverse and count connected cells, and then tracking the maximum count encountered.

inputFormat

The first line contains two integers n and m, the number of rows and columns respectively.

Each of the next n lines contains a string of length m consisting of characters 'L' and 'W'.

You should read from standard input (stdin).

outputFormat

Output a single integer, the size of the largest island. Print the result to standard output (stdout).

## sample
5 5
LWLWL
WLLLW
LWLWL
LWLLW
WLLWL
9