Given a graph G = (V, E) compute all-pairs shortest paths where each shortest path uses exactly k interme-
diate vertices. Note: Several of these vertices may be repeating as shown in the example. Give an algorithm
with O(log k \cdot n³) running time. (Hint: How many edges are there in a path with k intermediate vertices?)
5
$v_1$
$v_4$
2
4
5
10
2
1
2
$v_2$
$v_3$
$v_5$
Figure 1: The shortest path with k = 3 intermediate vertices from $v_1$ to $v_5$ is $v_1 \to v_3 \to v_2 \to v_3 \to v_5$ for
a total cost of w($v_1$, $v_3$) + w($v_3$, $v_2$) + w($v_2$, $v_3$) + w($v_3$, $v_5$) = 4 + 1 + 1 + 2 = 8