Data Structures & AlgorithmsModerateCodeforces Div 2 C

Directed graph on vertices 0 to 5 with positive weights (u→v (w)): 5→4 (2), 3→5 (2), 5→0 (3), 4→1 (1), 5→2 (3), 3→1 (1), 4→0 (3), 1→4 (3), 0→1 (2), 2→5 (1), 4→3 (2), 2→3 (3), 1→0 (3), 0→4 (1), 1→5 (1), 0→3 (1). How many different paths from 0 to 5 have the minimum possible total weight? Two paths are different if their vertex sequences differ.

  1. A. 2
  2. B. 1
  3. C. 3
  4. D. 4

Correct answer: D. 4

The minimum weight is 3. Propagating path counts along tight edges (d[u] + w = d[v]) gives 4. Keeping a single parent gives 1, and counting shortest-hop routes (2) answers a different question.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic