#C4357. Largest Contiguous Terrain Area
Largest Contiguous Terrain Area
Largest Contiguous Terrain Area
You are given a grid of characters representing various types of terrain. Each cell in the grid represents a terrain type, and two cells are considered adjacent if they share a common edge.
Your task is to determine the size of the largest contiguous region (i.e. connected component) composed of cells with the same terrain type.
For instance, if you have a grid with cells marked by characters, you need to count the maximum number of adjacent cells (vertically or horizontally) that have identical values.
Conceptually, you can view the grid as a graph where each cell is a vertex and an edge exists between two vertices if the corresponding cells share a side. The problem then reduces to finding the size of the largest connected component in this graph.
inputFormat
The first line contains two integers \(n\) and \(m\), where \(n\) is the number of rows and \(m\) is the number of columns in the grid.
Each of the following \(n\) lines contains a string of length \(m\) representing a row of the grid.
outputFormat
Output a single integer which is the size of the largest contiguous area consisting of the same terrain type.
## sample5 5
ffff*
mff*m
mmmm*
*wfff
www**
6
</p>