Graphs & Trees

Bridges, shortest paths, LCA, centroid decomposition, and tree DP through 10 problems.

52 lessons
177 min

Lessons

1. Introduction to Advanced Graphs

Beyond basic traversals

2m

2. Techniques Overview

What you'll learn

3m

3. Codeforces 732F Tourist Reform - Problem Statement

CF 732F - maximize min edge-connectivity

3m1 problems

4. Codeforces 732F Tourist Reform - Why Naive Fails

Trying all orientations is exponential

3m

5. Tourist Reform - Key Insight

Bridge tree and 2-edge-connected components

3m

6. Codeforces 732F Tourist Reform - Solution

Contract $2$-edge-connected components

3m

7. Codeforces 732F Tourist Reform - Implementation

Bridge finding and component contraction

5m1 problems

8. Codeforces 732F Tourist Reform - Example and Complexity Analysis

Linear in graph size

3m

9. Codeforces 652E Pursuit For Artifacts - Problem Statement

CF 652E - path through special edge

3m1 problems

10. Codeforces 652E Pursuit For Artifacts - Solution

Query on bridge tree

3m

11. Codeforces 652E Pursuit For Artifacts - Implementation

Bridge tree path query

5m1 problems

12. Codeforces 652E Pursuit For Artifacts - Example and Complexity Analysis

Linear preprocessing

3m

13. Codeforces 545E Paths and Trees - Problem Statement

CF 545E - minimum weight shortest path tree

3m1 problems

14. Codeforces 545E Paths and Trees - Solution

Greedy edge selection in Dijkstra

3m

15. Codeforces 545E Paths and Trees - Implementation

Modified Dijkstra with tie-breaking

5m1 problems

16. Codeforces 450D Jzzhu and Cities - Problem Statement

CF 450D - remove redundant railways

3m1 problems

17. Codeforces 450D Jzzhu and Cities - Why Naive Fails

Checking each railway independently

3m

18. Codeforces 450D Jzzhu and Cities - Solution

Track shortest path sources

3m

19. Codeforces 450D Jzzhu and Cities - Implementation

Dijkstra with path counting

5m1 problems

20. Codeforces 450D Jzzhu and Cities - Example and Complexity Analysis

Single Dijkstra run

3m

21. Codeforces 786B Legacy - Problem Statement

CF 786B - edges to ranges

3m1 problems

22. Codeforces 786B Legacy - Why Naive Fails

Too many edges

3m

23. Legacy - Key Insight

Segment tree as graph nodes

3m

24. Codeforces 786B Legacy - Solution

Segment tree graph

3m

25. Codeforces 786B Legacy - Implementation

Build segment tree graph

5m1 problems

26. Codeforces 786B Legacy - Example and Complexity Analysis

Logarithmic edges per operation

3m

27. Codeforces 1051F The Shortest Statement - Problem Statement

CF 1051F - almost-tree shortest paths

3m1 problems

28. Codeforces 1051F The Shortest Statement - Why Naive Fails

Dijkstra per query is too slow

3m

29. The Shortest Statement - Key Insight

Near-tree structure exploitation

3m

30. Codeforces 1051F The Shortest Statement - Solution

LCA on tree plus special vertices

3m

31. Codeforces 1051F The Shortest Statement - Implementation

Precompute special vertex distances

5m1 problems

32. Codeforces 1051F The Shortest Statement - Example and Complexity Analysis

Leverages sparse extra edges

3m

33. Codeforces 609E Minimum Spanning Tree for Each Edge - Problem Statement

CF 609E - MST containing specific edge

3m1 problems

34. Codeforces 609E Minimum Spanning Tree for Each Edge - Solution

Maximum edge on MST path

3m

35. Codeforces 609E Minimum Spanning Tree for Each Edge - Implementation

LCA with max edge tracking

5m1 problems

36. Codeforces 609E Minimum Spanning Tree for Each Edge - Example and Complexity Analysis

MST plus LCA queries

3m

37. Codeforces 1495D BFS Trees - Problem Statement

CF 1495D - count valid BFS trees

3m1 problems

38. Codeforces 1495D BFS Trees - Solution

Layer by layer counting

3m

39. Codeforces 1495D BFS Trees - Implementation

Product of valid parent counts

5m1 problems

40. Codeforces 1495D BFS Trees - Example and Complexity Analysis

Quadratic in vertices

3m

41. Codeforces 771C Bear and Tree Jumps - Problem Statement

CF 771C - sum of jump distances

3m1 problems

42. Codeforces 771C Bear and Tree Jumps - Why Naive Fails

Quadratic pair enumeration

3m

43. Bear and Tree Jumps - Key Insight

Modular distance counting for contribution

3m

44. Codeforces 771C Bear and Tree Jumps - Solution

Contribution by distance mod k

3m

45. Codeforces 771C Bear and Tree Jumps - Implementation

Tree DP with mod k tracking

5m1 problems

46. Codeforces 771C Bear and Tree Jumps - Example and Complexity Analysis

Linear with small k factor

3m

47. Codeforces 519E A and B and Lecture Rooms - Problem Statement

CF 519E - count equidistant vertices

3m1 problems

48. Codeforces 519E A and B and Lecture Rooms - Why Naive Fails

Linear counting per query

3m

49. Codeforces 519E A and B and Lecture Rooms - Solution

Find midpoint via LCA

3m

50. Codeforces 519E A and B and Lecture Rooms - Implementation

LCA with subtree size queries

5m1 problems

51. Quiz: Graphs and Trees

Test your understanding

5m1 problems

52. Section Recap

What you've learned

3m

Ready to start learning?

Access all 52 lessons with interactive content and progress tracking.