Data Structures & AlgorithmsVery hardICPC regional · GATE CS top band

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

Correct answer: D. 6

Dijkstra pops F at 5 and finalises it, then A at 6 via F; when E (7) is popped later, the edge E→F (−4) cannot improve the finalised F, so it reports 6. The true shortest is C→E→F→A = 4, 3 is the true distance to F, and using |−4| gives 12 via E.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic