~/algor $ cat problems/matritsa-orollar-soni
Number of islands
Medium
1000 ms
128 MB
59%
A map of size $n \times m$ is given: $1$ is land, $0$ is water. Land cells touching by their top, bottom, left or right side form one island (touching diagonally does not count). Find the number of islands on the map.
Input
The first line contains two positive integers $n$ and $m$. Each of the next $n$ lines contains $m$ numbers ($0$ or $1$).
Output
One integer — the number of islands.
Note
$1 \le n, m \le 200$
$a_{i,j} \in \{0, 1\}$
Examples
Input #1
4 5 1 1 0 0 1 1 0 0 1 1 0 0 1 0 0 1 0 1 0 1
Output #1
5
Input #2
2 2 1 0 0 1
Output #2
2