Data Structures & AlgorithmsVery hardGATE CS · ICPC regional

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

  1. A. 4
  2. B. 14
  3. C. 8
  4. D. 6

Correct answer: D. 6

Dijkstra finalises E at distance 5 before the negative edge from D is seen, so it reports 6. 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