Expand_the_pond

here is the link for my code


i am getting tle in many test caseā€¦please help me what can i optimise to avoid tle.

@ankitkumarmbill1
You have implemented brute force method. Time complexity of your code is O(M^2 * N^2) which will give tle.
Instead of doing this way, mark every pond and numbered them and try to find whether it is possible of connect any two pond or not.

I hope Iā€™ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.