Algorithm. Floyd-Warshall [00RT]

Initialize s[u,v] according to the base cases
\mathit {next}[u,u] \gets u for u \in V
\mathsf {for} k \gets 1 \dots n:
\mathsf {for} u \gets 1 \dots n:
\mathsf {for} v \gets 1 \dots n:
\mathsf {if} s[u,k] < \infty \land s[k,v] < \infty \land s[u,k] + s[k,v] < s[u,v]:
s[u,v] \gets s[u,k] + s[k,v]
\mathit {next}[u,v] \gets \mathit {next}[u,k]

After the algorithm is finished, to reconstruct the shortest path from u to v, we simply look up each step along the path using the \mathit {next} matrix. First we look up \mathit {next}[u,v] = u_2, then we look up \mathit {next}[u_2,v] = u_3, and so on, until reaching v.