Dynamic Programming with Rerooting (Rerooting DP) - Preparation to IOI Part 5