harbor run -t openthoughts/tasktrove-exp-rpt-pymethods2test-large-pymethods2test-2755
harbor download openthoughts/tasktrove-exp-rpt-pymethods2test-large-pymethods2test-2755
Implement a function that checks if a directed graph contains a cycle.
The function is_cyclic must accept two parameters:
is_cyclic
V
adj
adj[i]
i
The method should return a boolean value:
True
False
# Example 1: Cycle exists V = 4 adj = [[1], [2], [0], [3]] assert is_cyclic(V, adj) == True # Example 2: No cycle V = 4 adj = [[1], [2], [3], []] assert is_cyclic(V, adj) == False
/app/solution.py
The implementation should follow the provided function signature:
def is_cyclic(V, adj): ...