digraph acyclic detect implementation