We essentially want to root the tree at TT and always move to the parent of the current node until we end up at TT.

Hint 1

Hint 2

Hint 3

Solution

Join the USACO Forum!

Stuck on a problem, or don't understand a module? Join the USACO Forum and get help from other competitive programmers!