Help in solving FORESTGA (https://www.codechef.com/practice/LP2TO303/problems/FORESTGA?tab=statemen)

I am getting partial correct in this.
Can anyone help find the cause?
https://www.codechef.com/viewsolution/1018592665