Data Structures & AlgorithmsHardCodeforces Div 2 C · GATE CS

A directed graph with no directed cycles has arcs u→v (weight) : I→X (0), I→C (8), I→T (7), X→C (2), C→T (-3), T→Z (0). Weights may be negative. What is the minimum total weight of a path from I to Z that uses at most 3 arcs?

  1. A. 5
  2. B. 4
  3. C. 6
  4. D. 7

Correct answer: A. 5

Plain Bellman–Ford with k rounds (relaxing only through paths of length at most 3) gives 5. Ignoring the limit gives -1, and only paths of exactly 3 arcs give 5.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic