Write a function to detect a cycle in a directed graph using the DFS algorithm.
HardProblem Statement
Write a function to detect a cycle in a directed graph using the DFS algorithm.
Sample Input
Graph: { 0: [1], 1: [2], 2: [0], 3: [4], 4: [] }Sample Output
Cycle detected: true
Limits
Time: 2s · Memory: 256 MB