Data Structures & AlgorithmsHardCodeforces Div 2 C · ICPC regional
A directed acyclic graph on vertices 0 to 6 has exactly these edges (u→v means u must come before v): 1→3, 2→0, 2→3, 2→5, 4→0, 4→1, 4→3, 5→0, 5→4, 6→2, 6→3. How many linear orders of all 7 vertices respect every edge (topological orderings)?
- A. 6
- B. 26
- C. 5040
- D. 3
Correct answer: D. 3
Counting orders with a subset DP gives 3. Dropping one edge from the constraints gives 6, and n! = 5040 ignores all constraints; both are the slips.
Practise more Trees, Graphs, Recursion and Dynamic Programming questionsTrees, Graphs, Recursion and Dynamic Programming: notes and key points
More Trees, Graphs, Recursion and Dynamic Programming questions
- A directed acyclic graph on vertices 0 to 5 has exactly these edges (u→v means u must come before v): 0→1, 1→3, 1→5, 2→0, 2→1, 2→3, 2→4…
- A directed acyclic graph on vertices 0 to 5 has exactly these edges (u→v means u must come before v): 0→5, 2→0, 3→1, 3→2, 3→5, 4→0, 4→2…
- A directed acyclic graph on vertices 0 to 4 has exactly these edges (u→v means u must come before v): 0→2, 1→0, 3→2, 4→0, 4→2. How many…
- A directed acyclic graph on vertices 0 to 6 has exactly these edges (u→v means u must come before v): 0→4, 1→2, 3→5, 5→0, 5→1, 5→4, 6→0…
- A directed acyclic graph on vertices 0 to 5 has exactly these edges (u→v means u must come before v): 0→3, 1→2, 3→2, 4→1, 5→0, 5→3. How…
- A directed acyclic graph on vertices 0 to 5 has exactly these edges (u→v means u must come before v): 1→0, 1→2, 1→5, 2→0, 4→5, 5→2, 5→3…