Parallel Courses III
Examples
Example 1:
Input: n = 3, relations = [[1,3],[2,3]], time = [3,2,5]
Output: 8
Explanation:
Example 2:
Input: n = 5, relations = [[1,5],[2,5],[3,5],[3,4],[4,5]], time = [1,2,3,4,5]
Output: 12
Example 1:
Input: n = 3, relations = [[1,3],[2,3]], time = [3,2,5]
Output: 8
Explanation:
Example 2:
Input: n = 5, relations = [[1,5],[2,5],[3,5],[3,4],[4,5]], time = [1,2,3,4,5]
Output: 12
You are given an integer n, which indicates that there are n courses labeled from 1 to n. You are also given an array relations where relations[i] = [prevCoursei, nextCoursei] and a 1-indexed array time where time[i] is the time needed to complete the (i + 1)th course.
You may start taking a course at any time if all of its prerequisite courses have been completed.
Return the minimum number of months needed to complete all courses.
Courses 1 and 2 can be taken in parallel and finish by month 3. Course 3 then takes 5 more months.
1 <= n <= 5 * 10^40 <= relations.length <= min(n * (n - 1) / 2, 5 * 10^4)relations[i].length == 21 <= prevCoursei, nextCoursei <= nprevCoursei != nextCoursei1 <= time[i] <= 10^4