Expand the Pond

In the editorial, it is suggested to use flood-fill but I am getting TLE using flood-fill. Please help me with my code.
Here is my implementation:

@Rhinorox
why are you creating visited[n][m] array everytime inside the nested loop. You don’t have time much memory. Also the way you declared visited array in function is wrong. please go through the editorial once again

  1. I am creating visited array for every dry pond because for the next dry pond, previous’s visited data is useless to me
  2. I don’t think using ‘memset’ instead of ‘for loop’ to assign values(0 and -1) would be a problem
    Now I have gone through the editorial, their explanation is pretty vague, so please point out my mistake explicitly’