Implementation of a directed graph, and associated DFS, Cycle detection algorithms