Can't get rid of runtime error while making the dfs-order to store in an array

This is the link to my code in which I just scanned the inputs…and stored the dfs-order in an array.But this code is getting runtime error due to array out of index range when I submit it in Factor Tree question…I have removed rest of code and have only given the code which causes runtime error.Please help I am stuck from 2 weeks in removing this runtime error.When I try with my test cases it works fine.but when I try to submit it in Factor Tree question it shown runtime error.
I used the DFS-order to calculate the LCA for the 2 nodes.But this is not much of use for now as I have removed all the rest of code and just eft a code which scan all the inputs and just make the dfs-order.
FCTRE Problem - CodeChef. ← Link to the question.