NZEC error for ABROADS.Worked for one day but still not able to get the glitch.

Problem Link : ABROADS

Solution Link : JAVA

Here I’m getting NZEC for Task # 0 and Task # 3.I have used the bfs approach.P array for population and D array to store the edges.I have not been able to find the reason for NZEC.Please help me.

Change the dfs function to iterative dfs, the solution would be accepted.

The reason for NZEC in java is that Java has lower stack limit which would throw Stack-overflow Error.

Alternatively, you can create a new thread for each recursive call which would allocate extra stack memory. I have modified your code. Look at here

Happy Programming!

EDIT: You can look at my submission during contest for 30 points

1 Like

Thanks ankur.I tried both bfs and dfs.Actually I have used the bfs approach here by using a queue after I realized the memory limit of dfs recursive call.But this queue approach is also not working.It is still giving me an NZEC for Task#0 and Task#3.
I tried submitting the modified code.Its giving me WA.

why I am I getting NZEC in sub task 1