Appleman and Tree

CodeForces - 461B