WA in impossible boss on spoj.

I am trying to solve the problem impossible boss on spoj. Its giving wrong answer for certain cases. I think there is some problem in my lazy propogation . Can someone please tell the problem in my code. The link to the question is: http://www.spoj.com/problems/DCEPC11I/ Here is the link to my code: http://ideone.com/LcGbrb