Data Structures & AlgorithmsHardGATE CS · Codeforces Div 2 B

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

  1. A. 10
  2. B. 13
  3. C. 12
  4. D. 14

Correct answer: B. 13

Plain Bellman–Ford with k rounds (relaxing only through paths of length at most 2) gives 13. Ignoring the limit gives 10, and only paths of exactly 2 arcs give 13.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic