help me to solve below q (cpp soln is must)
You are given a matrix with N rows and M columns. Each cell is either dry or has water. We say that two cells are neighbours if they share one of their four sides. A pond is a maximal subset of cells containing water such that any cell is accessible from any other cell by moving only along neighbours. You should add water to exactly one cell in order to maximise the size of the pond.
Input Format
The first line contains two integers N and M. Each of the next N lines contains M integers: 0 for a dry cell and 1 for a cell containing water.
Constraints
1 ≤ N,M ≤ 1000 There is at least one dry cell and one cell filled with water in the matrix.
Output Format
Print a single integer representing the largest possible size of the pond.
Sample Input
3 3
0 1 1
0 0 1
0 1 0
Sample Output
5
Explanation
Watering the cell at coordinates [2,2] unites the 2 ponds with sizes 1 and 3, resulting a pond of size 5, including the newly watered cell.