Need help! I am tried to solve SPOJ [QTREE4](http://www.spoj.com/problems/QTREE4/). I used centroid decomposition, but still getting TLE (time limit exceeded). In my code, a query is processed in _O(log(n)^2)_. How can I improve complexity? Any suggestions. [Here](https://paste.ubuntu.com/p/gQfZG84q5v/) is my code.