#P3074. [USACO13FEB] Milk Scheduling S
[USACO13FEB] Milk Scheduling S
Description
Farmer John has cows (), numbered from to . Milking cow takes units of time. Due to the barn layout, some cows must finish milking before others can start. For example, if cow must be milked before cow , then cow must be completely milked before starting cow .
To finish as quickly as possible, John has hired many workers and can milk any number of cows simultaneously. However, the precedence constraints must still be respected. Compute the minimum total time to finish all milking.
Input Format
- The first line: two integers (number of cows) and (number of constraints, ).
- Lines through : each line contains one integer , the milking time of cow ().
- Lines through : each line contains two integers and , meaning cow must be completely milked before starting cow . All constraints are acyclic, so a solution is guaranteed.
Output Format
- One line: the minimum total time to complete all milking.
3 1
10
5
6
3 2
11
Hint
There are cows with milking times . Cow must finish before cow .
Initially, cows and can be milked simultaneously (taking and ). After cow finishes, start cow (total time ).
Translated by ChatGPT 5
京公网安备 11011102002149号