Data Structures & AlgorithmsVery hardCodeforces Div 2 C · ICPC regional

A directed acyclic graph on vertices 0 to 5 has exactly these edges (u→v means u must come before v): 1→5, 3→0, 3→4, 3→5, 4→0, 4→1, 4→2, 4→5. How many linear orders of all 6 vertices respect every edge (topological orderings)?

  1. A. 12
  2. B. 24
  3. C. 37
  4. D. 720

Correct answer: A. 12

Counting orders with a subset DP gives 12. Dropping one edge from the constraints gives 24, and n! = 720 ignores all constraints; both are the slips.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic