Can Someone help me here -

Problem - http://codeforces.com/contest/600/problem/E .

Spoiler [Alert] - Proceed further only if you have done this question and submitted or You have no plan to submit this question (But want to help me :P).

**If you want to give this question a try then open this only after trying the question.**

## Click to view

My soln - http://codeforces.com/contest/600/submission/38786344 .

Editorial -

http://codeforces.com/blog/entry/21827

Please explain me this also -

Editorial Approach - for Each moving can be done in O(logn) time And why ML/TLE will not be there in worst case.

In my opinion worst case.

n=100000.

Colors all distinct.

vertices -

i i+1 i.e. tree is **bamboo** . Only 1 and n has one neighbour. And 1<i<n have neighbours i-1,i+1