Ostap and Tree

CodeForces - 735E