Given course durations and prerequisite relations, return the minimum total time needed to finish all courses when multiple independent courses can run in parallel. Pattern focus: Indegree. Track the earliest finish time for each node while processing the DAG in topological order.
n = number of courses, relations = prerequisite pairs, time = duration of each course
minimum total time to finish all courses
Example 1:
Input:
n = 3 relations = [[1,3],[2,3]] time = [3,2,5]
Output:
8
Explanation:
Courses 1 and 2 run in parallel for 3 and 2 units; then course 3 takes 5 more units.
Example 2:
Input:
n = 2 relations = [[1,2]] time = [1,2]
Output:
3
Example 3:
Input:
n = 4 relations = [[1,2],[2,3],[3,4]] time = [1,1,1,1]
Output:
4
Explanation:
A chain forces sequential completion.