Misha and LCP on Tree

CodeForces - 504E