Tree Queries Codecraft IIITH 2015 on Codeforces

I have written the following code for the problem Queries on Trees,Codecraft IIITH 2015 on codeforces(not live).
Problem link:

Here is a link to my solution:

The complexity is around O(q*log(n)) for all the print queries.
And for the updates it is logn for each value to be updated.I don’t think we can do better than that.This however gives a TLE verdict.Any suggestions?