Data Structures & AlgorithmsVery hardGATE CS · Codeforces Div 2 C

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

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

Correct answer: B. 10

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

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic