Data Structures & AlgorithmsVery hardCodeforces Div 2 C · GATE CS

A directed graph with no directed cycles has arcs u→v (weight) : K→Q (2), K→N (-3), K→I (8), J→L (3), J→I (8), Q→N (7), Q→L (6), N→L (0), L→I (-1). Weights may be negative. What is the minimum total weight of a path from K to I that uses at most 2 arcs?

  1. A. -4
  2. B. 8
  3. C. -3
  4. D. 7

Correct answer: B. 8

Within 2 arcs, K reaches I only by the direct arc (8); no 2-arc route ends at I. K→N→L→I = −4 needs 3 arcs, −3 is the distance to L, and 7 is the 3-arc route K→Q→L→I.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic