GATE Computer ScienceVery hardGATE CS (PYQ pattern)

A directed graph on vertices 0–4 has edges (weight): 0→1 2, 1→2 3, 0→2 9, 2→3 1, 1→3 8, 3→4 2, 2→4 7, 0→3 12, 1→4 15. What is the minimum cost of a walk from 0 to 4 that uses exactly 3 edges?

  1. A. 8
  2. B. 12
  3. C. 10
  4. D. 14

Correct answer: B. 12

The min-plus cube of the weight matrix gives D³[0][4] = 12 (for example 0→1→3→4 = 2 + 8 + 2, 0→2→3→4 = 9 + 1 + 2, 0→1→2→4 = 2 + 3 + 7). The unrestricted shortest path 0→1→2→3→4 = 8 uses 4 edges, so it does not apply.

More Algorithms questions

Exams that ask this topic