P1451 Count the Number of Cells
Description
A rectangular array consists of digits $0$ to $9$. Digits $1$ to $9$ denote cells. Two positions belong to the same cell if, moving up, down, left, or right through positions with cell digits, they are connected. Given the array, count the number of cells.
Input Format
The first line contains two integers $n$ and $m$.
The next $n$ lines each contain a string of length $m$ consisting only of characters `0` to `9`, representing the $n \times m$ matrix.
Output Format
Output a single integer, the number of cells.
Explanation/Hint
Constraints
For $100\%$ of the testdata, $1 \le n, m \le 100$.
Translated by ChatGPT 5