Data Structures & AlgorithmsVery hardICPC regional · GATE CS top band

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

  1. A. 5
  2. B. 12
  3. C. 4
  4. D. 11

Correct answer: A. 5

Dijkstra finalises E at distance 4 before the negative edge from D 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