directed cycle detection