#P5382. [THUPC 2019] 改善生活
[THUPC 2019] 改善生活
Description
"Improve Life" is a group chat created by Xiao Z. In the group chat, Xiao Z and his friends (there are members in total; Xiao Z is numbered , and his friends are numbered from to ) talk about everything and have a great time. However, chatting too much is often labeled as being the "chat king", which gives Xiao Z a headache.
Today, Xiao Z foresees that there may be topics in the group (numbered from to ). Topic is a topic that member (possibly Xiao Z himself) is interested in. This means that if this topic appears, this member will make an intense speech for minutes. For convenience, you may assume that apart from this, members will not make intense speeches.
Among all topics, there are guiding relationships. Each guiding relationship is an ordered pair , meaning that if topic appears, it will definitely cause topic to appear.
Coincidentally, Xiao Z发现 that among all of his own different topics, there is no direct or indirect guiding relationship.
Because the midterm exams are coming, all members except Xiao Z are busy studying, so they will not proactively start topics (starting a topic means making a topic appear; same below). That is, all topics with can only be triggered directly or indirectly by guiding relationships. This puts Xiao Z in a dilemma: he wants to chat a lot, but also wants to get rid of the "chat king" label. Therefore, he decides to proactively start one or more topics that he is interested in, to induce other topics to appear, so that the ratio of the maximum intense speaking time among other members to Xiao Z's own intense speaking time is as large as possible. That is, maximize the following expression:
$$\frac{\max\limits_{k=2}^n \text{sum}\left(k\right)}{\text{sum}\left(1\right)}$$Here, denotes the sum of values over all topics that appear and that member is interested in.
To avoid precision errors, you only need to output the result of rounding down the maximum value.
Input Format
The first line contains two positive integers , representing the number of topics (which is also exactly the number of group members) and the number of guiding relationships.
The second line contains positive integers (), describing the member number who is interested in each topic in order. It is guaranteed that there exists at least one such that .
The third line contains positive integers (), describing the time of intense speech for the member interested in each topic.
The next lines describe the guiding relationships. Each line contains two positive integers (), describing a guiding relationship . See the Description for the exact meaning. It is guaranteed that between any two different topics with , there is neither a direct nor an indirect guiding relationship.
For each line, if it contains multiple numbers, they are separated by a single space.
Constraints: , .
Output Format
Output a single integer on one line: the result of rounding down the maximum value of the required expression, i.e., the largest integer not exceeding that value.
7 8
2 2 1 1 3 3 4
100 100 40 20 100 50 40
1 3
2 3
1 4
2 4
3 5
4 6
3 7
4 7
2
Hint
Sample Explanation
Xiao Z can choose to start topics numbered 3 and 4. This will cause topics numbered 5, 6, and 7 to appear, and trigger an intense speech of minutes by member 3, and minutes by member 4. Since member 3 speaks for a longer time, and Xiao Z's own intense speaking time is minutes, the maximum ratio is , and rounding it down gives .
It can be proven that Xiao Z has no better strategy.
Copyright Information
From THUPC (THU Programming Contest, Tsinghua University Programming Contest) 2019.
Resources such as solutions can be found at https://github.com/wangyurzee7/THUPC2019.
Translated by ChatGPT 5
京公网安备 11011102002149号