Data Structures & AlgorithmsHardCodeforces Div 2 D · ICPC regional

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

  1. A. 11
  2. B. 16
  3. C. 15
  4. D. 18

Correct answer: B. 16

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

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic