#K58712. Infinite Paint Spread
Infinite Paint Spread
Infinite Paint Spread
In this problem, you are given a grid with width W and height H. Initially, K cells in the grid are painted, with their coordinates provided as input. The paint spreads iteratively to the four adjacent cells (up, down, left, right) from any painted cell. This process continues until no new cell can be painted.
A cell at position \( (x,y) \) is considered painted if it can be reached from an initially painted cell via a sequence of moves in the four cardinal directions. Note that the grid is 1-indexed, so each cell satisfies \(1 \le x \le W\) and \(1 \le y \le H\).
Your task is to determine the total number of painted cells after the paint has spread infinitely.
inputFormat
The input begins with a single line containing three space-separated integers: W, H, and K.
If K is greater than zero, each of the next K lines contains two space-separated integers x and y, representing the coordinates of an initially painted cell.
If K is zero, there will be no additional lines.
outputFormat
Output a single integer representing the total number of cells painted after the infinite spreading of the paint.
## sample5 4 2
1 2
3 3
20
</p>