#K85872. Counting Clusters of Empty Cells

    ID: 36738 Type: Default 1000ms 256MiB

Counting Clusters of Empty Cells

Counting Clusters of Empty Cells

You are given a grid of dimensions \(n \times m\). Each cell in the grid is either empty (denoted by .) or blocked (denoted by #). Two empty cells are considered connected if they are adjacent vertically or horizontally.

Your task is to count the number of connected clusters of empty cells in the grid. A cluster is a maximal group of connected empty cells.

You may use Depth-First Search (DFS) or Breadth-First Search (BFS) algorithms to solve the problem.

inputFormat

The first line contains two integers (n) and (m) representing the number of rows and columns respectively. Each of the following (n) lines contains a string of (m) characters. A character '.' represents an empty cell, and a character '#' represents a blocked cell.

outputFormat

Output a single integer denoting the number of connected clusters of empty cells in the grid.## sample

4 5
.#...
..#..
.##..
#..#.
3