Conservative graph time excedded, don't know the cause

My solution is giving correct answer but is exceding time. I have seen others solutions and i am unable to know why my solution takes time as compared to others, i have used normal logic. Help me if you know where i am lagging. also tell if there is more efficient logic…
Here is my commented solution: https://www.codechef.com/viewsolution/34909605

Consider what happens when you create four huge arrays each testcase