Data Structures & AlgorithmsHardGATE CS · Codeforces Div 2 C

Directed acyclic graph on vertices 0 to 5 with weighted edges (u→v (w)): 2→1 (9), 1→5 (9), 3→4 (9), 2→4 (8), 4→5 (9), 3→5 (5), 0→1 (1), 1→4 (8). What is the largest total weight of a directed path that starts at 0 and ends at 5?

  1. A. 10
  2. B. 9
  3. C. 18
  4. D. 26

Correct answer: C. 18

Processing vertices in topological order gives 18. The shortest-path distance (10) minimises instead of maximising, and letting the path start anywhere (26) ignores the required start at 0.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic