Data Structures & AlgorithmsVery hardGATE CS · ICPC regional

Directed weighted graph on vertices A, D, C, E, F (source A, target F) with edges: A→D (5); A→C (6); C→D (-6); D→F (4); C→F (4); A→F (14); A→E (5). Run Dijkstra from A 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 F does it report?

  1. A. 4
  2. B. 9
  3. C. 10
  4. D. 14

Correct answer: B. 9

Dijkstra finalises D at distance 5 before the negative edge from C is seen, so it reports 9. The true shortest distance is 4, 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