Data Structures & AlgorithmsHardCodeforces Div 2 D · ICPC regional

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

  1. A. 13
  2. B. 16
  3. C. 33
  4. D. 19

Correct answer: D. 19

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

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic