CF884E Binary Matrix
Description
You are given a matrix of size $ n×m $ . Each element of the matrix is either 1 or 0. You have to determine the number of connected components consisting of 1's. Two cells belong to the same component if they have a common border, and both elements in these cells are 1's.
Note that the memory limit is unusual!
Input Format
The first line contains two numbers $ n $ and $ m $ ( $ 1
Output Format
Print the number of connected components consisting of 1's.
Explanation/Hint
In the first example the matrix is:
`
0001
1010
1000
`It is clear that it has three components. The second example: `
01011111
11100011
`It is clear that the number of components is 2. There are no 1's in the third example, so the answer is 0.
0001
1010
1000
`It is clear that it has three components. The second example: `
01011111
11100011
`It is clear that the number of components is 2. There are no 1's in the third example, so the answer is 0.