Implement an algorithm to detect cycles in a dependency graph for a data pipeline orchestrator at Character.AI.