Parallel Courses III
You are given an integer n (courses labeled 1..n), a list of prerequisite pairs relations where [a, b] means course a must finish before course b starts, and an array time where time[i] is the months course i+1 takes. Any number of courses may run in parallel, and a course may begin the instant all its prerequisites are done. Return the minimum number of months to complete all courses. The graph is guaranteed to be a DAG.
Open official problem prompt ↗Find the minimum wall-clock months to finish all courses when every course can run in parallel but must wait for its prerequisites — i.e. the length of the longest weighted dependency chain.
Think of a construction project: many crews work simultaneously, but the roof crew cannot start until the walls are up and the walls cannot start until the foundation cures. The whole build takes as long as the slowest chain of dependent tasks — the critical path — not the sum of every task.
- Input
- n = 3, relations = [[1,3],[2,3]], time = [3,2,5]
- Output
- 8
- Why
- Courses 1 (3mo) and 2 (2mo) run in parallel from month 0; course 3 waits for both, so it starts at month 3 and finishes at 3 + 5 = 8.
1 <= n <= 5 * 10^40 <= relations.length <= min(n * (n - 1) / 2, 5 * 10^4)relations[j].length == 21 <= prevCourse_j, nextCourse_j <= nprevCourse_j != nextCourse_jAll the pairs [prevCourse_j, nextCourse_j] are uniquetime.length == n1 <= time[i] <= 10^4The given graph is a directed acyclic graph