← 返回 amazon 的题目列表Total Completion Time for Packages with Dependencies
类型:online_judge
amazon
Problem Description
Given a set of packages, each with dependencies on other packages and associated with a certain completion time. A package can only start after all its dependent packages have been completed. Calculate the total time required to complete all packages.
Input
n (int): The number of packages.
times (List[int]): An integer array of size n where times[i] indicates the completion time for package i.
dependencies (List[Tuple[int, int]]): An array of m dependencies where each element (a, b) means package b depends on package a.
Output
total_time (int): The total time required to complete all packages.
Examples
Example 1:
Input:
n = 3
times = [3, 6, 1]
dependencies = [(0, 1), (1, 2)]
Output: 10
Example 2:
Input:
n = 3
times = [1, 2, 3]
dependencies = [(0, 1), (0, 2)]
Output: 4
Notes
Each package takes at least one unit of time to complete.
No cyclic dependencies.
Example
Input
3
3 6 1
0 1
1 2