An intermediate vertex of a simple path p = <v1, v2, .., vl>is any vertex of p other than v1 and vl.
The Floyd-Warshall (FW) algorithm works by successively reducing the number of intermediate vertices that can occur in a shortest path and its subpaths.
Let graph G = (V, E) have vertices V numbered 1 .. n, V = {1, 2, .., n}, and consider a subset {1, 2, .., k} for some k.
Let p be the minimum weight path from vertex i to vertex j whose intermediate vertices are drawn from {1, 2, .., k}. One of two situations then occur: