6 subtopics · 20 problems
Trees
Rooted trees, tree DFS, subtree queries, LCA, diameter, Euler tour, and heavy-light decomposition.
01Tree DFS & Subtree Queries
DFS on trees, subtree size, depth computation.
2 easy1 medium2 hard
| Problem | Difficulty | Link |
|---|---|---|
| 1843CSum in Binary Tree | easy | Solve |
| 580CKefa and Park | easy | Solve |
| 1843DApple Tree | medium | Solve |
| 1324FMaximum White Subtree | hard | Solve |
| 1881FMinimum Maximum Distance | hard | Solve |
02Tree Diameter & Center
Find the longest path in a tree (two BFS/DFS).
1 medium3 hard
| Problem | Difficulty | Link |
|---|---|---|
| 1900CAnji's Binary Tree | medium | Solve |
| 1092FTree with Maximum Cost | hard | Solve |
| 1187ETree Painting | hard | Solve |
| 1881FMinimum Maximum Distance | hard | Solve |
03LCA & Binary Lifting
Lowest common ancestor queries in O(log n).
2 medium2 hard
| Problem | Difficulty | Link |
|---|---|---|
| 1843DApple Tree | medium | Solve |
| 1328ETree Queries | medium | Solve |
| 1837EPlayoff Fixing | hard | Solve |
| 519EA and B and Lecture Rooms | hard | Solve |
04Euler Tour & Flatten
Flatten a tree into an array for range query data structures.
1 medium2 hard
| Problem | Difficulty | Link |
|---|---|---|
| 1324FMaximum White Subtree | medium | Solve |
| 1092FTree with Maximum Cost | hard | Solve |
| 838BDiverging Directions | hard | Solve |
05Heavy-Light Decomposition (HLD)
Decompose a tree into chains for path queries + updates.
2 hard
| Problem | Difficulty | Link |
|---|---|---|
| 838BDiverging Directions | hard | Solve |
| 487ETourists | hard | Solve |
06Centroid Decomposition
Recursively split the tree at centroids — enables O(n log²n) path queries.
2 hard
| Problem | Difficulty | Link |
|---|---|---|
| 342EXenia and Tree | hard | Solve |
| 321CCiel and Gondola | hard | Solve |
Was this helpful?