#P10541. [THUPC 2024 决赛] 研发计划

[THUPC 2024 决赛] 研发计划

Problem Description

Seeing that several large-model startup companies have recently obtained huge funding, as an “alchemy master” you feel tempted and decide to enter the market and build products yourself.

After some整理 (sorting things out), you find that there are currently mm kinds of products that will sell very well after being launched. After launching product ii, the expected profit is gig_i. These mm products involve nn kinds of technologies. There are pp technology-product dependency relations (u,v)(u,v), meaning technology uu is a prerequisite technology for product vv. For each product, you must obtain all its prerequisite technologies before you can launch it.

For technology jj, you can choose to pay a cost fjf_j to buy it directly from other companies, or pay a cost hjh_j to obtain it through R&D. R&D requires certain conditions: there are qq technology-technology dependency relations (a,b)(a,b), meaning technology aa is a prerequisite technology for technology bb. Then, you can obtain technology jj through R&D only after you have obtained all prerequisite technologies of technology jj. If a technology has no prerequisites, then you can obtain it directly through R&D. It is guaranteed that the technology-technology dependency relations form a directed acyclic graph, i.e., no cyclic dependencies will occur (and naturally there will be no self-loops).

The profit of a plan equals the total profit of the launched products minus the total cost of obtaining technologies. Now, as a businessman, you want to research some technologies and launch some products to maximize your profit. For simplicity, you only need to output the maximum profit value.

Input Format

The first line contains four positive integers n,m,p,qn,m,p,q. It is guaranteed that 2n1002 \le n \le 100, 1m1001 \le m \le 100, 1pnm1 \le p\leq nm, 1qn(n1)21 \le q\leq \frac{n(n-1)}{2}, representing the total number of technologies, the total number of products, the number of technology-product dependency relations, and the number of technology-technology dependency relations.

The next line contains nn integers fif_i, representing the cost of buying technology ii directly.

The next line contains nn integers hih_i, representing the cost of researching technology ii based on its prerequisite technologies.

The next line contains mm integers gig_i, representing the profit obtained after launching product ii.

The next pp lines each contain two integers ui,viu_i,v_i, representing a technology-product dependency relation (ui,vi)(u_i,v_i). It is guaranteed that 1uin1 \le u_i \le n, 1vim1 \le v_i \le m, and all input (ui,vi)(u_i,v_i) are pairwise distinct.

The next qq lines each contain two integers ai,bia_i,b_i, representing a technology-technology dependency relation (ai,bi)(a_i,b_i). It is guaranteed that 1aibin1 \le a_i \ne b_i \le n, all input (ai,bi)(a_i,b_i) are pairwise distinct, and they do not form cyclic dependencies.

It is guaranteed that all input numbers are non-negative integers not exceeding 10910^9.

Output Format

Output an integer, representing the maximum profit among all plans.

4 5 5 3
2 10 6 7
1 7 5 3
2 2 3 8 8
1 1
2 2
2 3
3 4
4 5
1 2
2 3
3 4
8

Hint

The optimal plan is to research technology 1, buy technology 3, and research technology 4 in order. Then we can launch products 1, 4, and 5. The profit is (2+8+8)(1+6+3)=8(2+8+8)-(1+6+3)=8.

Source and Acknowledgements

From the THUPC2024 (Tsinghua University Student Programming Contest and Invitational Contest) Finals. Thanks to THUSAA for providing this problem.

For testdata, statement, reference solution, editorial, etc., please refer to the official THUPC repository: https://thusaac.com/public.

Translated by ChatGPT 5