#K86427. Counting Islands

    ID: 36862 Type: Default 1000ms 256MiB

Counting Islands

Counting Islands

You are given a 2D grid map consisting of R rows and C columns, where each cell is either '1' (land) or '0' (water). An island is defined as a group of adjacent lands connected 4-directionally (up, down, left, right). Your task is to count the number of islands present in the grid.

The grid dimensions can be expressed in LaTeX as \( R \times C \). Solve this problem using techniques such as Depth-First Search (DFS) to traverse and mark visited land cells.

inputFormat

The input is given from standard input (stdin). The first line contains two integers \( R \) and \( C \) representing the number of rows and columns respectively. This is followed by \( R \) lines, each containing a string of length \( C \) that represents a row of the grid.

outputFormat

Print a single integer to standard output (stdout) — the total number of islands found in the grid.

## sample
4 5
11000
11000
00100
00011
3