Data Structures & AlgorithmsHardCodeforces Div 2 D · ICPC regional

Directed graph on vertices 0 to 5 with non-negative weights (u→v (w)): 0→4 (17), 0→1 (3), 1→2 (1), 3→5 (10), 3→4 (1), 2→3 (1), 4→5 (1), 4→3 (19). What is the minimum total weight of a path from 0 to 5 that uses AT MOST 3 edges?

  1. A. 7
  2. B. 15
  3. C. 46
  4. D. 18

Correct answer: D. 18

Dynamic programming over the number of edges gives 18. The unconstrained shortest path (7) uses too many edges, allowing 4 edges gives 15, and insisting on exactly 3 edges gives 46.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic