NZEC error for FIRESC problem. Help needed!

This is the link to my code ==>> https://www.codechef.com/viewsolution/8869656

I have used vector array to make adjacency list and run DFS on it without Stack implementation, with the help of a parent array. Still I cant why is it throwing NZEC error. Out of Memory flow is not there because I have tested it on the boundary condition.

That recursion seems really deep. Are you sure DFS() won’t overflow some java limit?

You should prefer iteration where possible anyway…

Try your own (very long and evil) input.
If you get really desperate, you could try masking exceptions on parts of your program until the system gives WA instead of NZEC.

PS: 1340 MB used RAM sure looks alarming