Data Structures & AlgorithmsVery hardGATE CS · Codeforces Div 2

Directed weighted graph on vertices A, D, B, F, C (source A, target C) with edges: A→D (4); A→B (7); B→D (-6); D→C (3); B→C (1); A→C (12); A→F (7). 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 C does it report?

  1. A. 8
  2. B. 12
  3. C. 7
  4. D. 4

Correct answer: C. 7

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