Data Structures & AlgorithmsVery hardCodeforces Div 2 D · ICPC regional

A directed weighted graph has the arcs u→v (weight): F→K (4), F→U (1), F→H (13), K→F (12), U→F (13), U→K (4), U→L (8), L→F (2), L→K (2), L→U (2), L→H (1), H→K (14), H→L (4). You may choose at most 2 arcs and make each of them cost 0 (the arcs keep their directions). What is the minimum possible cost of a path from F to H?

  1. A. 10
  2. B. 11
  3. C. 0
  4. D. 1

Correct answer: C. 0

Dijkstra on states (vertex, number of free arcs used) gives 0; the optimum may free arcs that are not on the cheapest path. Freeing the heaviest arc of the shortest path greedily gives 1, and no free arcs gives 10.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic