Data Structures & AlgorithmsVery hardGATE CS · Codeforces Div 2 C

Directed graph on vertices 0 to 6 with weighted edges (u→v (w)): 5→0 (4), 3→5 (4), 2→3 (1), 2→5 (4), 5→2 (2), 5→1 (5), 3→2 (7), 0→1 (2), 1→2 (8), 2→6 (1), 4→1 (8), 2→1 (4), 3→6 (9), 2→0 (12), 6→5 (8), 3→0 (6), 4→5 (6), 0→3 (2), 1→0 (7), 4→2 (11), 3→1 (1). What is the length of a shortest path from 0 to 6, where the length is the sum of edge weights?

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

Correct answer: A. 9

Dijkstra finalises vertices in increasing distance and gives 9 via 0 → 3 → 5 → 2 → 6. Counting edges instead of weights picks a route with 2 edge(s) and weight 11, which is the common slip.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic