Data Structures & AlgorithmsModerateGATE CS · Codeforces Div 2 C

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

  1. A. 12
  2. B. 2
  3. C. 18
  4. D. 10

Correct answer: D. 10

Relaxing in topological order with max instead of min gives 0 → 2 → 5 = 2 + 8 = 10. Letting the path start at 1 finds 1 → 4 → 5 = 12, 2 counts arcs instead of weight, and 18 adds the longest and shortest (0 → 4 → 5 = 8) routes.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic