Approach hintTry it first, then revealHide
An apple starting at x can only end at a leaf of the subtree of x, and the two apples move independently. Precompute the number of leaves in every subtree with one DFS and multiply, using 64-bit values.
An apple starting at x can only end at a leaf of the subtree of x, and the two apples move independently. Precompute the number of leaves in every subtree with one DFS and multiply, using 64-bit values.