Data Structures & AlgorithmsVery hardGATE CS · ICPC regional

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

  1. A. 4
  2. B. 5
  3. C. 8
  4. D. 10

Correct answer: B. 5

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