Data Structures & AlgorithmsVery hardCodeforces Div 2 D · ICPC regional

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

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

Correct answer: C. 5

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

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic