#K41817. Counting Plant Clusters
Counting Plant Clusters
Counting Plant Clusters
You are given a farm grid with m rows and n columns. Each cell in the grid is either 1
(indicating a plot with plants) or 0
(indicating an empty plot). Your task is to determine the number of distinct clusters of plants in the grid.
A cluster is defined as a group of adjacent cells with the value 1
that are connected horizontally or vertically (diagonal connections are not considered).
Note: Read the input from standard input and print the result to standard output.
inputFormat
The first line contains two integers m and n separated by a space. Then, there are m lines each containing n space-separated integers (either 0 or 1) representing the grid.
outputFormat
Output a single integer representing the number of clusters of plants found in the grid.## sample
3 3
1 1 0
0 1 0
1 0 1
3
</p>