Use the transitive closure algorithm given in the book.