Data Structures, Algorithms, & Applications in C++
Chapter 19, Exercise 15
Since we are interested only in the existence of a path,
we can change c(i,j,k) to be a
boolean valued method.
c(i,j,k) is false iff there is
no path from vertex i to vertex j
that has no intermediate vertex larger than
k.
With this change, we see that
c(i,j,0) is false
iff i != j and
there is
no edge from vertex i to vertex j.
Further, the recurrence for
c(i,j,k) can be rewritten
using logical operators. The new equation is
c(i,j,k) = c(i,j,k-1) || (c(i,k,k-1) && c(k,j,k-1), k > 0