Issue with editorial solution

The solution provided in editorial did not pass all test cases. Don’t know why but I changed visited array to bool visited[n]={0} and it worked. Please verify this once. If only I had the issue or anyone else.

Hello @Atul-Sagar-3137455909651980,

Yes, it is giving wrong output.
The reason for giving all correct after using visited[n]={0} is the initialization of the array with all false which is missing in the editorial.

You can also correct the editorial by adding the following statements:
for(int i=0;i<n;i++)
visited[i]=false;

Hope, this would help.

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.