- Naveen
- Karthik
There are N pet animals arranged in R rows and C columns. The
cells which contain pet animals are marked with the value 1. There
are certain pet animals infected by a contagious disease and they
are marked by -1 (that is instead of 1, they will be denoted by
-1). The disease will spread to any adjacent animals (left, right,
top, bottom, top-left, top-right, bottom-left, bottom-right)
infecting them too. The program must print the final count H of
pet animals which are not infected.
The first line contains R and C separated by a space. The next R lines, each containing C columns indicating the details.
Input:
1 0 1 0 -1
1 0 0 0 1
0 0 1 1 0
1 0 1 0 0
Output:
4
Blue: Healthy
Red: Infected
Using DFS algorithm.