Click Here i have tried 2 days but i didn't find any solution.i seached in google i found some solution but i couldn't understand of those code. i know LCA,HLD,dfs,segmeent tree.And solved some problem in differnt Oj. So, anyone can help me by sharing an idea how can i solve this problem.And also how can i implement this.
It is about Mo's algorithm on trees. http://codeforces.com/blog/entry/43230
:):)
You are welcome :)