Can anybody help me to find what’s wrong with this code here. The problem link here. Any testcase where it fails will be helpful. Thanks.
P.S.- I have already solved it using bfs+coloring so I am not looking for alternate approaches just curious why this is wrong.

You can write data generator, and then run your own correct program and error program so that you can know where it is wrong?