Homework
Time limit2sMemory limit512 MB
Given a DAG of assignments with durations, remove one vertex to minimize the makespan of the remaining precedence-constrained schedule.
- Level
Medium6 of 10
- Topics
- Graph, Topological sort, Dynamic programming, Greedy
- Solved
- No attempts yet
Problem
Seryozha hates doing homework, but in the last computer science lesson the teacher gave the class different homework assignments. Some assignments can only be done after certain others have been done.
For each assignment Seryozha estimated how many minutes it would take him to do it. He then realized that he definitely would not have time to do all the assignments. So he decided to do all of them except one: for a single undone assignment the teacher probably will not scold him too badly. Now Seryozha has to choose which assignment not to do.
Help Seryozha choose an assignment he can skip so that he finishes all the remaining assignments as quickly as possible.
Input
The first line of the input file contains the integers and , the number of assignments and the number of dependencies between assignments (, ). The second line contains integers: . The number is the number of minutes Seryozha needs to do assignment ().
Then follow lines, each containing two integers. The numbers and mean that assignment must be done before assignment . It is guaranteed that all assignments can be done.
Output
Print one number to the output file: the minimum number of minutes Seryozha needs to do all assignments except one.
Hint
In the example above Seryozha can skip the fourth assignment. The remaining assignments take 11 minutes in total.