A build system tracks n components numbered 0 through n - 1. You are given edges, a list of directed dependency pairs (u, v), where a pair means component u must be built before component v.
Part 1: Cycle Detection
Return true if the directed dependency graph contains at least one cycle. Otherwise return false.
Part 2: Finding an Edge to Remove
Using the same input format, if the graph contains a cycle, return any single directed edge [u, v] such that deleting exactly that edge makes the entire graph acyclic. If the graph is already acyclic, return [-1, -1].
There may be multiple acceptable edges; returning any one is allowed. You may assume that whenever a cycle exists, there is at least one edge whose removal breaks all cycles.
Part 1 Examples
Example 1:
Input: n = 5, edges = [[0,1],[0,2],[1,3],[2,3],[3,4]]
Output: false
Explanation: The graph is a DAG; one valid build order is 0, 2, 1, 3, 4.
Example 2:
Input: n = 4, edges = [[0,1],[1,2],[2,0],[2,3]]
Output: true
Explanation: The directed cycle 0 -> 1 -> 2 -> 0 prevents any valid full ordering.
Part 2 Examples
Example 3:
Input: n = 4, edges = [[3,0],[0,2],[1,2]]
Output: [-1,-1]
Explanation: The graph is already acyclic, so no edge needs to be removed.
Example 4:
Input: n = 6, edges = [[0,1],[1,2],[2,1],[2,3],[3,4],[4,5]]
Output: [2,1]
Explanation: Deleting [2,1] removes the cycle 1 -> 2 -> 1, leaving an acyclic graph. Returning [1,2] would also be accepted.
Constraints: