#P9341. [JOIST 2023] 警卫 / Security Guard

[JOIST 2023] 警卫 / Security Guard

Description

In JOI Kingdom, there are NN islands, numbered from 11 to NN. Each island has the insecurity level. The insecurity level of the island i (1iN)i\ (1 \le i \le N) is SiS_i.

In JOI Kingdom, ships between pairs of islands are mostly used as the methods of transportations. There are MM ships, numbered from 11 to MM. The ship j (1jM)j\ (1 \le j \le M) connects the island AjA_j and the island BjB_j. We can run ships when necessary. It is possible to travel from any island to any other island by taking a number of ships.

In JOI Kingdom, there is a plan to introduce new ships. We can choose any pairs of islands where newly introduced ships connect.

One day, an incident occurred. A ship at anchor was attacked. Prime minister K of JOI Kingdom decided to introduce new ships. He also demands that ships in JOI Kingdom should satisfy the following Security Condition.

  • When a ship is anchored at the island i (1iN)i\ (1 \le i \le N), the number of security guards on the ship is greater than or equal to SiS_i.

However, since it is expensive to hire security guards, we want to minimize the number of hired security guards. As long as the condition “it is possible to travel from any island to any other island by taking a number of ships” is satisfied, it is possible to abolish ships which are currently running.

Therefore, we will run ships as follows. Here, kk is the number of newly introduced ships.

  1. For each of the kk newly introduced ships, we choose two islands where it connects.
  2. We choose a number of (more than or equal to 00) ships, and we abolish them. It is allowed to abolish newly introduced ships.
  3. For each of the ships, we anchor it at one of the two islands where it connects. We make a number of security guards get on it. Moreover, the following conditions should be satisfied.

Condition     For every pair u,v (1uN,1vN)u, v\ (1 \le u \le N, 1 \le v \le N) of islands, it is possible to transport a passenger from the island uu to the island vv by repeating the following operations a number of times. In the process, Security Condition should be satisfied all the time.

  • We make a passenger or security guards get on a ship which is anchored at the island where the passenger or security guards are staying.
  • We make a passenger or security guards get off a ship at the island where the ship is currently anchored.
  • We move a ship from the island where the ship is currently anchored to the other island where the ship connects.

Since the budget is limited, we can introduce at most QQ new ships. For each k (0kQ)k\ (0 \le k \le Q), Prime minister K wants to know the minimum possible number of hired security guards if the number of newly introduced ships is kk. Write a program which, given the information of islands and the routes of the ships and the number of new ships we can introduce, calculates the minimum possible number of hired security guards for each kk.

Input Format

Read the following data from the standard input.

N M QN\ M\ Q

S1 S2  SNS_1\ S_2\ \cdots\ S_N

A1 B1A_1\ B_1

A2 B2A_2\ B_2

\vdots

AM BMA_M\ B_M

Output Format

Write Q+1Q+1 lines to the standard output. The (k+1)(k+1)-th line (0kQ)(0 \le k \le Q) of output should contain the minimum possible number of hired security guards if the number of newly introduced ships is kk.

4 3 0
2 1 3 2
1 2
2 3
3 4

7

4 3 1
2 1 3 2
1 2
2 3
3 4

7
5

3 3 0
1 1 1
1 2
1 3
2 3

2

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

14
8 7 0
16 39 36 23 15 48 23 56
1 2
1 3
2 4
2 5
3 6
3 7
7 8

245
10 13 4
314 159 265 358 979 323 846 264 338 327
1 2
1 4
2 3
2 5
3 6
4 5
4 7
5 6
5 8
6 9
7 8
8 9
9 10

3139
2901
2722
2567
2461

Hint

【样例解释 #1】

If the number of newly introduced ships is 00, we need 77 security guards. For example, the conditions are satisfied if we allocate the ships and 77 security guards as follows.

  • The ship 11 is initially anchored at the island 22, and two security guards get on the ship 11.
  • The ship 22 is initially anchored at the island 22, and two security guards get on the ship 22.
  • The ship 33 is initially anchored at the island 44, and three security guards get on the ship 33.

Let us explain how to transport a passenger in the following two cases.

  • We transport a passenger from the island 11 to the island 44.
  • We transport a passenger from the island 33 to the island 22.

We can transport a passenger from the island 11 to the island 44 as follows. The islands where the ships 1,2,31, 2, 3 are anchored, and the numbers of security guards on the ships 1,2,31, 2, 3 are written in this order. The numbers of security guards on the islands 1,2,3,41, 2, 3, 4 are written in this order.

We can transport a passenger from the island 33 to the island 22 as follows.

Since it is impossible to satisfy the conditions if the number of security guards is less than or equal to 66, output 77.

This sample input satisfies the constraints of Subtasks 2,3,4,5,6,72, 3, 4, 5, 6, 7.

【样例解释 #2】

If the number of newly introduced ships is 00, similarly as Sample Input 11, we need 77 security guards.

If the number of newly introduced ships is 11, we need 55 security guards. For example, the conditions are satisfied if we allocate the ships and 55 security guards as follows.

  • We introduce a new ship connecting the island 22 and the island 44. (In the following, we call it the ship 44.)
  • We abolish the ship 33.
  • We initially anchor the ship 11 at the island 22, and make two security guards get on the ship 11.
  • We initially anchor the ship 22 at the island 22, and make one security guard get on the ship 22.
  • We initially anchor the ship 44 at the island 22, and make two security guards get on the ship 44.

This sample input satisfies the constraints of Subtasks 5,6,75, 6, 7.

【样例解释 #3】

If the number of newly introduced ships is 00, we need 22 security guards. For example, the conditions are satisfied if we allocate the ships and 22 security guards as follows.

  • We abolish the ship 33.
  • We initially anchor the ship 11 at the island 11, and make one security guard get on the ship 11.
  • We initially anchor the ship 22 at the island 11, and make one security guard get on the ship 22.

This sample input satisfies the constraints of Subtasks 4,5,6,74, 5, 6, 7.

【样例解释 #4】

This sample input satisfies the constraints of all the subtasks.

【样例解释 #5】

This sample input satisfies the constraints of Subtasks 3,4,5,6,73, 4, 5, 6, 7.

【样例解释 #6】

This sample input satisfies the constraints of Subtasks 5,6,75, 6, 7.

【数据范围】

对于所有测试数据,满足:

  • 2N2×1052 \le N \le 2\times 10 ^ 5;
  • N1M4×105N - 1 \le M \le 4\times 10 ^ 5;
  • 0Q2×1050 \le Q \le 2\times 10 ^ 5;
  • 1Si109 (1iN)1 \le S_i \le 10 ^ 9\ (1 \le i \le N);
  • 1Aj<BjN (1jM)1 \le A_j < B_j \le N\ (1 \le j \le M);
  • (Ax,Bx)(Ay,By) (1x<yM)(A_x, B_x) \neq (A_y, B_y)\ (1 \le x < y \le M);
  • It is possible to travel from any island to any other island by taking a number of ships;
  • Given values are all integers.
子任务编号 分值 特殊限制
11 1212 M=N1M = N - 1Q=0Q = 0Si2 (1iN)S_i \le 2\ (1 \le i \le N)Aj=jA_j = jBj=j+1 (1jM)B_j = j + 1\ (1 \le j \le M)
22 1313 M=N1M = N - 1Q=0Q = 0Aj=jA_j = jBj=j+1 (1jM)B_j = j + 1\ (1 \le j \le M)
33 1212 M=N1M = N - 1Q=0Q = 0
44 1313 Q=0Q = 0
55 88 N16N \le 16
66 1818 N3000N \le 3 000
77 2424