Data Structures & AlgorithmsVery hardCodeforces 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): 0→2, 0→4, 3→2, 3→5, 3→6, 5→4, 6→2, 6→4. How many linear orders of all 7 vertices respect every edge (topological orderings)?
- A. 161
- B. 133
- C. 147
- D. 5040
Correct answer: B. 133
Counting orders with a subset DP gives 133. Dropping one edge from the constraints gives 161, 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
- Directed graph on vertices 0 to 5 with edges: 0→1, 1→2, 4→1, 1→3, 1→4, 2→0, 4→5. How many strongly connected components does it have…
- Directed graph on vertices 0 to 8 with edges: 6→8, 5→7, 6→7, 3→1, 6→3, 3→8, 3→4, 1→0, 0→1, 8→4, 1→5, 7→3, 2→6, 3→6, 4→8. How many strongly…
- Directed graph on vertices 0 to 5 with edges: 4→2, 0→5, 5→0, 0→1, 0→3, 5→4, 4→0, 3→1, 0→2, 3→0. How many strongly connected components…
- Directed graph on vertices 0 to 7 with edges: 4→1, 3→0, 1→6, 5→6, 6→7, 5→3, 6→5, 3→6, 5→4, 5→0, 4→2, 4→5, 1→2, 5→7, 2→1. How many strongly…
- Directed graph on vertices 0 to 8 with edges: 6→0, 0→2, 1→8, 3→5, 0→5, 1→0, 1→3, 5→8, 5→0, 4→6, 5→7, 6→7, 8→1, 3→4. How many strongly…
- Directed graph on vertices 0 to 5 with edges: 5→4, 2→3, 4→3, 3→1, 1→0, 2→5, 4→1, 4→2, 0→1. How many strongly connected components does it…