Data Structures & AlgorithmsHardGATE CS · Codeforces Div 2 C

Directed graph on vertices 0 to 6 with weighted edges (u→v (w)): 6→3 (12), 0→6 (12), 3→6 (3), 0→2 (4), 4→1 (1), 6→1 (6), 5→6 (6), 0→5 (3), 3→0 (1), 4→2 (9), 3→2 (8), 5→3 (11), 1→5 (3), 3→4 (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. 12
  3. C. 4
  4. D. 13

Correct answer: A. 9

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

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic