Number of Islands
Given a grid of land and water, count the number of islands.
Input format
The first line contains R and C. The next R lines contain 0/1 values (1 = land).
Output format
Print the number of islands (4-directional connectivity).
Constraints
- Values fit in a 64-bit signed integer
- Trailing whitespace and a trailing newline are ignored by the judge
Read from stdin, write to stdout. Sample cases below show the exact format.
Sample cases
Example 1
Input
12 2
0 1
1 0
0 0
0 0
1 0
0 1
1 0
1 0
0 0
0 1
0 0
1 1Expected output
7Example 2
Input
1 11
1 0 1 1 0 1 1 0 0 1 1Expected output
4