Data Structures & AlgorithmsHardGATE CS · Codeforces Div 2 C

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

  1. A. 16
  2. B. 6
  3. C. 14
  4. D. 19

Correct answer: C. 14

Dijkstra finalises vertices in increasing distance and gives 14 via 0 → 1 → 4 → 7. Counting edges instead of weights picks a route with 2 edge(s) and weight 16, which is the common slip.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic