Implement a function to determine the minimum number of courses a student needs to take to complete their main courses given a list of course dependencies. The implementation should utilize a graph representation to manage the dependencies.
n (int): The total number of courses (1 <= n <= 1000).
k (int): The number of main courses (1 <= k <= n).
main_courses (List[int]): A list of integers representing the main courses, where each integer lies in the range from 0 to n-1.
dependencies (List[List[int]]): A list of lists where each sub-list at index i contains integers that represent the courses that need to be completed before taking course i.
Output Requirements
If a cycle exists in the course dependencies, return -1.
If no cycles exist, return a tuple:
An integer representing the total number of courses that need to be taken.
A list of integers representing the courses in the order they should be taken (1-indexed).
Implementation Notes
Utilize the provided Graph class, which includes methods for adding edges, performing depth-first search, and detecting cycles.
Employ the bootstrap decorator provided in the code to handle generator functions.
File Requirements
Implement the function in a file called /app/solution.py. Make sure the file follows standard Python conventions and includes appropriate docstrings for clarity.