detect cycle in Digraph or toposort