Data Structures & AlgorithmsVery hardCodeforces Div 2 C · GATE CS

A directed graph with no directed cycles has arcs u→v (weight) : V→K (4), V→X (3), K→F (-1), K→X (-2), F→X (8), X→W (8). Weights may be negative. What is the minimum total weight of a path from V to W that uses at most 2 arcs?

  1. A. 10
  2. B. 2
  3. C. 19
  4. D. 11

Correct answer: D. 11

Two Bellman–Ford rounds from copied distances allow at most 2 arcs: V→X→W = 3 + 8 = 11. The 3-arc path V→K→X→W = 10 is too long, 2 stops at X, and 19 goes V→K→F→X→W.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic