Data Structures & AlgorithmsVery hardCodeforces Div 2 · ICPC regional

Directed weighted graph on vertices D, C, E, F, B (source D, target B) with edges: D→C (6); D→E (7); E→C (-4); C→B (4); E→B (5); D→B (11); D→F (5). Run Dijkstra from D with a min-heap: a vertex is finalised the first time it is popped, its outgoing edges are relaxed then, and a finalised vertex's distance is never changed afterwards (edges into finalised vertices are ignored). What distance to B does it report?

  1. A. 11
  2. B. 7
  3. C. 12
  4. D. 10

Correct answer: D. 10

Dijkstra finalises C at distance 6 before the negative edge from E is seen, so it reports 10. The true shortest distance is 7, which goes through the negative edge; clamping negatives to 0 or using their absolute values are other wrong models.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic