Logic is correct as far as I think but getting WA on test cases, PLZ HELP
Getting WA of test cases
@Akshay123
What you are doing is taking every parent separately and visiting its neighbours. But the proper way of doing is to run the DFS completely i.e. take the not visited node and visit all the possible nodes from it.
In your approach you are not marking the childs as visited dfs_helper function, so what will happen is since you have counted them as child for one node but later on some another node can also consider them as their child because visited[] is false for them.
So use DFS properly, your logic is almost correct.
Feel free to ask if you need any help in implementing the code.
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.