Data Structures & AlgorithmsHardCodeforces Div 2 D · ICPC regional

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

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

Correct answer: A. 6

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

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic