LGSEG Help needed!

I tried to solve the problem LGSEG problem link using:

binray-search & dfs

but my submission is giving Runtime error on the 3rd test case and i am not able to figure out why. Can someone please suggest some test case where my code might be getting into RTE.
Submission link: Solution: 49364717 | CodeChef