#P5477. [MtOI2018] 刷题?作业狂魔!
[MtOI2018] 刷题?作业狂魔!
Description
You have minutes.
The order of doing homework can be sorted by importance , but this may not be the best strategy. Also, each type of homework may have more than one item, so each homework also has a quantity , and each item takes minutes to complete.
Before doing some homework, it may be necessary to finish some other homework first, so relations are given. Each relation contains two numbers , , meaning that is a prerequisite for completing . There is no case where .
The relations may contain cycles. cz does not want to redo homework, so he can only skip the homework that lies on cycles.
If the time ends when a homework is only half done, then you gain no importance from that homework. If for a homework you finish only items, and , then you gain importance. If you do not finish all items of that homework, then you are not allowed to do any other homework.
A homework may have multiple prerequisites . However, note that once one prerequisite of a homework is done, that homework can be done. But cz is very focused: after finishing one homework, he must do the homework that uses this homework as a prerequisite.
Input Format
The input has lines.
Line contains two positive integers .
The next lines follow. Line contains three positive integers .
Line contains one positive integer .
The next lines describe the relations, with the same meaning as above.
Output Format
Output one line with one number, the maximum value (importance).
4 7
2 1 1
2 1 2
2 1 3
2 1 4
3
3 4
2 3
1 2
6
Hint
Subtasks
For of the testdata, .
All other values are within the range of .
Source
Problem setter: Doubleen
56432
Translated by ChatGPT 5
京公网安备 11011102002149号