eolymp
bolt
Try our new interface for solving problems
Problems

Avoid The Lakes

Avoid The Lakes

Farmer John's farm was flooded in the most recent storm, a fact only aggravated by the information that his cows are deathly afraid of water. His insurance agency will only repay him, however, an amount depending on the size of the largest "lake" on his farm. The farm is represented as a rectangular grid with \textbf{N} (\textbf{1} ≤ \textbf{N} ≤ \textbf{100}) rows and \textbf{M} (\textbf{1} ≤ \textbf{M} ≤ \textbf{100}) columns. Each cell in the grid is either dry or submerged, and exactly \textbf{K} (\textbf{1} ≤ \textbf{K} ≤ \textbf{N} × \textbf{M}) of the cells are submerged. As one would expect, a lake has a central cell to which other cells connect by sharing a long edge (not a corner). Any cell that shares a long edge with the central cell or shares a long edge with any connected cell becomes a connected cell and is part of the lake. \InputFile \begin{itemize} \item Line \textbf{1}: Three space-separated integers: \textbf{N}, \textbf{M}, and \textbf{K} \item Lines \textbf{2}..\textbf{K}+\textbf{1}: Line \textbf{i}+\textbf{1} describes one submerged location with two space separated integers that are its row and column: \textbf{R} and \textbf{C} \end{itemize} \OutputFile \begin{itemize} \item Line \textbf{1}: The number of cells that the largest lake contains. \end{itemize}
Time limit 1 second
Memory limit 64 MiB
Input example #1
3 4 5
3 2
2 2
3 1
2 3
1 1
Output example #1
4