##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
Some distance problems resist DFS and DP. Centroid decomposition gives divide-and-conquer on trees.
(Divide and conquer on trees)
(When DFS and DP fail)
(The balance point of a tree)
(Every tree has one)
(Walk toward heavy subtrees)
(Walking through the process)
Why it works for divide-and...
Knowledge check
Recursive structure of cent...
(Each level halves the size)
Knowledge check
(Recursive centroid finding)
(Two different structures)
core idea for path problems
(The general pattern)
(CSES 2079)
(Problem link)
(Compute sizes with DFS)
(Move toward balance)
(Two-phase approach)
(Complete solution)
(Tracing the algorithm)
(summary)
Knowledge check
(CSES 2080)
(Problem link)
(Divide by centroid)
Count distances from centroid
Avoid counting paths within...
(The recursive structure)
(Complete solution)
(Example trace)
(Path counting with centroids)
Knowledge check
(CSES 2081)
(Problem link)
(Modify the counting step)
(Range query on distances)
(Range counting with map)
(Example with range)
(Range queries on paths)
Preprocessing for fast queries
(Problem recognition)
Knowledge check
(Choosing the right tool)
(Avoiding common mistakes)
(Why it's O(n log n))
(Memory usage)
(Beyond basic path counting)
(Common errors and fixes)
(Build your skills)
(Centroid definition)
(Decomposition depth)
(Path counting logic)
(What you learned)