#P16701. [MCO 2026] 制造连招

    ID: 19031 远端评测题 2000ms 1024MiB 尝试: 0 已通过: 0 显示难度普及+/提高− 上传者: 标签>动态规划 DP2026MCC/MCO(马来西亚)

[MCO 2026] 制造连招

Problem Description

Dragon Evirir is playing a video game, and it wants to maximize the total damage by casting skills continuously.

Evirir can use NN different skills, numbered 0,1,,N10, 1, \ldots, N - 1. For each skill ii, its color is CiC_i and its damage is DiD_i. There are MM skill links in total, and each link is a pair of skills (Ui,Vi)(U_i, V_i), where 0iM10 \le i \le M - 1.

A combo is a skill sequence of length l1l \ge 1, s0,s1,,sl1s_0, s_1, \ldots, s_{l - 1}, such that for all 0i<l10 \le i < l - 1, (si,si+1)(s_i, s_{i+1}) is one of the MM skill links. The problem guarantees that the skill links in the input do not form a cycle. In other words, it is impossible to build a combo that uses the same skill twice.

The total power of the combo is computed as follows. Let there be a multiplier BB, initially B=1B = 1. For i=0,1,,l1i = 0, 1, \ldots, l - 1, do the following in order:

  • If i=0i = 0, do nothing.
  • Otherwise:
    • If skills sis_i and si1s_{i - 1} have the same color, multiply BB by 22.
    • If skills sis_i and si1s_{i - 1} have different colors, set BB to 11.
  • Then, the power of skill sis_i is Dsi×BD_{s_i} \times B.

The total power of the combo is the sum of the powers of all cast skills.

For example, suppose a combo contains the following skills in order: (3,7)(3,7), (2,5)(2,5), (4,7)(4,7), (1,7)(1,7), (5,7)(5,7), (6,7)(6,7), (3,6)(3,6), where (x,y)(x, y) means a skill with damage xx and color yy. The computation is as follows:

s0s_0 s1s_1 s2s_2 s3s_3 s4s_4 s5s_5 s6s_6
Color CsiC_{s_i} 77 55 77 66
Damage DsiD_{s_i} 33 22 44 11 55 66 33
Multiplier BB 11 22 44 88 11
Power 3×1=33 \times 1 = 3 2×1=22 \times 1 = 2 4×1=44 \times 1 = 4 1×2=21 \times 2 = 2 5×4=205 \times 4 = 20 6×8=486 \times 8 = 48 3×1=33 \times 1 = 3

Therefore, the total power of this combo is 3+2+4+2+20+48+3=823 + 2 + 4 + 2 + 20 + 48 + 3 = 82.

Clearly, Evirir wants to cast a combo with the maximum total power. To do this, it installed a cheat that can change the color of any skill to a fixed color TT. Evirir can use this cheat at most KK times (that is, it can modify the colors of at most KK skills).

Find the maximum total power Evirir can achieve. If the maximum total power is strictly greater than 10910^9, output 1-1.

Input Format

The first line contains four integers NN, MM, KK, and TT, separated by spaces.

Then there are NN lines. The ii-th line contains two integers DiD_i and CiC_i, separated by a space.

Then there are MM lines. The ii-th line contains two integers UiU_i and ViV_i, separated by a space.

Output Format

Output one integer, the maximum possible total power. If it is strictly greater than 10910^9, output 1-1. If it is exactly equal to 10910^9, you should output 10910^9.

6 7 2 1
3 1
2 3
4 1
5 2
1 5
2 0
0 1
3 4
2 3
0 3
3 5
1 2
0 5
65
5 4 0 5
2 0
3 1
2 0
3 0
13 0
0 1
1 2
2 3
3 4
65
4 3 4 0
100000000 0
100000000 1
100000000 2
100000000 3
0 1
1 2
2 3
-1

Hint

Hint

Sample 1\underline{Sample\ 1}

This sample satisfies Subtasks 4 and 7.

A visualization is given below. An arrow from skill xx to skill yy means there is a skill link (x,y)(x, y), i.e., Evirir can use skill yy immediately after skill xx. The large circle in the upper-left corner explains what each number means.

:::align{center} :::

Evirir can change the colors of at most K=2K = 2 skills to color T=1T = 1. It can change the colors of skills 11 and 33 to 11, and then cast the skill sequence 012350 \to 1 \to 2 \to 3 \to 5. The total power is $(1 \times 3) + (2 \times 2) + (4 \times 4) + (8 \times 5) + (1 \times 2) = 65$.

An example that is not a combo is the skill sequence 03450 \to 3 \to 4 \to 5, because (4,5)(4, 5) is not one of the MM skill links.

Sample 2\underline{Sample\ 2}

This sample satisfies Subtasks 2, 3, 4, 5, 6, and 7.

There are N=5N = 5 skills and M=4M = 4 skill links. K=0K = 0, so Evirir cannot modify the color of any skill. The optimal combo is casting 012340 \to 1 \to 2 \to 3 \to 4. The total power is $(2 \times 1) + (3 \times 1) + (2 \times 1) + (3 \times 2) + (13 \times 4) = 65$.

Sample 3\underline{Sample\ 3}

This sample satisfies Subtasks 1, 3, 4, 5, 6, and 7.

Since K=4K = 4, Evirir can change the colors of skills 11, 22, and 33 to color T=0T = 0. The optimal combo is casting 01230 \to 1 \to 2 \to 3. The total power is $(10^8 \times 1) + (10^8 \times 2) + (10^8 \times 4) + (10^8 \times 8) > 10^9$. Since the maximum possible total power is strictly greater than 10910^9, output 1-1.

Scoring

For all testdata, the input satisfies the following Constraints:

  • 1N1041 \le N \le 10^4
  • $0 \le M \le \min\left(10^5, \frac{N(N - 1)}{2}\right)$
  • For all 0iN10 \le i \le N - 1, 1Di1081 \le D_i \le 10^8
  • For all 0iN10 \le i \le N - 1, 0CiN10 \le C_i \le N - 1
  • 0TN0 \le T \le N. Note that TT may equal NN, i.e., a color that is not used.
  • 0KN0 \le K \le N
  • For all 0iM10 \le i \le M - 1, 0Ui,ViN10 \le U_i, V_i \le N - 1 and UiViU_i \neq V_i
  • For all 0iM10 \le i \le M - 1, the pairs (Ui,Vi)(U_i, V_i) are all distinct.
  • It is guaranteed that the skill links do not form a cycle. In other words, it is impossible to build a combo that uses the same skill twice.
Subtask Points Additional Constraints
11 88 M=N1M = N - 1, and for all 0iM10 \le i \le M - 1, (Ui,Vi)=(i,i+1)(U_i, V_i) = (i, i + 1). K=NK = N
22 99 M=N1M = N - 1, and for all 0iM10 \le i \le M - 1, (Ui,Vi)=(i,i+1)(U_i, V_i) = (i, i + 1). K=0K = 0
33 3131 M=N1M = N - 1, and for all 0iM10 \le i \le M - 1, (Ui,Vi)=(i,i+1)(U_i, V_i) = (i, i + 1). N50N \le 50
44 1414 N50N \le 50
55 1717 M=N1M = N - 1, and for all 0iM10 \le i \le M - 1, (Ui,Vi)=(i,i+1)(U_i, V_i) = (i, i + 1). N300N \le 300
66 M=N1M = N - 1, and for all 0iM10 \le i \le M - 1, (Ui,Vi)=(i,i+1)(U_i, V_i) = (i, i + 1).
77 44 ---

Translated by ChatGPT 5