Critical path makespan
Your task
A build system runs n tasks (0..n-1), each with a positive duration durations[i]. Dependencies are pairs [a, b] meaning task b can only start after task a finishes; independent tasks run fully in parallel. Return the makespan, the minimum total time to finish all tasks given unlimited parallelism, which equals the longest dependency chain weighted by durations (the critical path). If the dependencies form a cycle, return -1.
Examples
critical_path(durations: list[int], deps: list[list[int]]) -> intExample 1
Input
critical_path([3, 2, 5, 1], [[0, 1], [1, 3], [0, 2], [2, 3]])Output
9