Graph Theory37 sections · 1633 units
Open in Course

Practice Tips (Getting comfortable)

(Solve 5 problems)

Start with CSES Tree Distances II. It is the cleanest rerooting problem with no edge cases. Once you solve it, try LeetCode 834834 (same problem, 00-indexed). Then move to problems where the combine function is not sum.

For each problem, follow this process: write the down pass first and verify it gives the correct answer for the root. Then add the up pass and verify on a small example by hand. Only then submit.

Aim to solve 55 rerooting problems. After that, the two-pass pattern becomes automatic and you can focus on designing the right down[v] and up[v] for each new problem.