Problem · Graph
Parallel Courses III
Learn this problemProblem statement
There are n courses labeled from 1 through n. You are given prerequisite relations and the duration of every course.
Each relation [previous, next] means course previous must be completed before course next can start. Course i takes time[i - 1] months.
You may take any number of courses concurrently whenever all of their prerequisites are complete. Return the minimum number of months needed to complete every course.
Function
minimumTime(n: int, relations: int[][], time: int[]) → intExamples
Example 1
n = 3relations = [[1,3],[2,3]]time = [3,2,5]return = 8Courses 1 and 2 start together. Course 3 starts after month 3, when both prerequisites are complete, and finishes five months later at month 8.
Example 2
n = 5relations = [[1,5],[2,5],[3,5],[3,4],[4,5]]time = [1,2,3,4,5]return = 12The critical chain is course 3, then course 4, then course 5, with total duration 3 + 4 + 5 = 12.
Constraints
1 <= n <= 5 * 10^40 <= relations.length <= min(n * (n - 1) / 2, 5 * 10^4)- Every relation contains two distinct course labels between
1andn. - All relations are unique, and the prerequisite graph is acyclic.
time.length == n1 <= time[i] <= 10^4