← 返回 oracle 的题目列表Simplified Course Scheduler
类型:online_judge
Given a set of courses and their prerequisite relations, which form a directed acyclic graph (DAG), write an algorithm to find all possible orders to take the courses. There are no multiple dependencies between courses. Output all possible learning paths.
Example: Input: Total courses = 4, Prerequisite relationships = [[1, 0], [2, 0], [3, 1], [3, 2]] Output: [[0, 1, 2, 3], [0, 2, 1, 3]]
Requirements:
Maximum number of courses is 1000.
In cases with multiple paths, the order of courses in each path should be in ascending order.
Note that paths may complete different courses and you should return all possible paths.
Example
Input
4
[[1, 0], [2, 0], [3, 1], [3, 2]]