Skip to content
  • Dashboard
  • Review
  • Go: plan & chat
  • Roadmap
  • Patterns & lessons49
  • Sheets
  • Problems1.5k
  • Ascend
  • Toolkit
  • Core CS + SQL
  • System Design
  • Machine Coding
  • Interview hub
  • Mock interview
  • Companies & OA
  • Leaderboard
  • Battles
  • College Cup
  • People

Keep your progress

Sync across devices with a free account.

Sign upSign in
Patterns & lessons
Sign inSign up
Patterns/Graphs/Graph BFS / DFS

Technique · CP 2400+

Dominator Tree

In a directed graph rooted at s, u dominates v if every s -> v path passes through u. The dominator tree (Lengauer-Tarjan, near-linear) answers 'which vertices lie on every path'. On a DAG, idom(v) is the LCA of v's predecessors, processed in topological order.

Learn firstGraph BFS / DFSTopological SortBinary Lifting & LCA
0%
mastery
0/2 solved
Practise nextCritical Cities
IdeaPracticePitfalls

Recognise it

The signal

directed graph: which cities must every route from 1 to n pass through

  1. 1Brute force

    Delete each vertex and re-test reachability: O(n(n + m)).

  2. 2The observation

    One reachability test per vertex.

  3. 3Why it works

    idom(v) is v's closest strict dominator, and v's dominators are exactly its ancestors in the tree.

Reach for it when

  • +vertices that lie on all shortest paths (shortest-path DAG)

Not when

  • ×undirected graphs (articulation points / block-cut-tree)

Practice

Next

Critical Cities

0/2 solved
  • Critical CitiesCSESHard
  • Visiting CitiesCSESHard

Pitfalls

Misconceptions

  • !using articulation points on a directed graph
Go deeperresources

Resources

  • Graph Theory playlistWilliam Fiset · video
  • Graph TraversalUSACO Guide · course
  • Disjoint Set Unioncp-algorithms · article
  • Dijkstracp-algorithms · article
  • Topological sortingcp-algorithms · article
  • Shortest paths visualizerVisuAlgo · tool
  • Graph cheatsheetTech Interview Handbook · article
TodayReviewPatternsProblems