Data Structures & AlgorithmsHardCodeforces Div 2 C

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

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

Correct answer: C. 2

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

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic