| 시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
|---|---|---|---|---|---|
| 3 초 | 1024 MB | 46 | 14 | 12 | 33.333% |
In JOI Kingdom, there are $N$ islands, numbered from $1$ to $N$. Each island has the insecurity level. The insecurity level of the island $i$ ($1 ≤ i ≤ N$) is $S_i$.
In JOI Kingdom, ships between pairs of islands are mostly used as the methods of transportations. There are $M$ ships, numbered from $1$ to $M$. The ship $j$ ($1 ≤ j ≤ M$) connects the island $A_j$ and the island $B_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.
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, $k$ is the number of newly introduced ships.
Condition: For every pair $u$, $v$ ($1 ≤ u ≤ N$, $1 ≤ v ≤ N$) of islands, it is possible to transport a passenger from the island $u$ to the island $v$ by repeating the following operations a number of times. In the process, Security Condition should be satisfied all the time.
Since the budget is limited, we can introduce at most $Q$ new ships. For each $k$ ($0 ≤ k ≤ Q$), Prime minister $K$ wants to know the minimum possible number of hired security guards if the number of newly introduced ships is $k$.
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 $k$.
Read the following data from the standard input.
$N$ $M$ $Q$
$S_1$ $S_2$ $\cdots$ $S_N$
$A_1$ $B_1$
$A_2$ $B_2$
$\vdots$
$A_M$ $B_M$
Write $Q+1$ lines to the standard output. The $(k+1)$-th line ($0 ≤ k ≤ Q$) of output should contain the minimum possible number of hired security guards if the number of newly introduced ships is $k$.
| 번호 | 배점 | 제한 |
|---|---|---|
| 1 | 12 | $M = N - 1$, $Q = 0$, $S_i ≤ 2$ ($1 ≤ i ≤ N$), $A_j = j$, $B_j = j + 1$ ($1 ≤ j ≤ M$). |
| 2 | 13 | $M = N - 1$, $Q = 0$, $A_j = j$, $B_j = j + 1$ ($1 ≤ j ≤ M$). |
| 3 | 12 | $M = N - 1$, $Q = 0$. |
| 4 | 13 | $Q = 0$. |
| 5 | 8 | $N ≤ 16$. |
| 6 | 18 | $N ≤ 3\,000$. |
| 7 | 24 | No additional constraints. |
4 3 0 2 1 3 2 1 2 2 3 3 4
7
If the number of newly introduced ships is $0$, we need $7$ security guards. For example, the conditions are satisfied if we allocate the ships and $7$ security guards as follows.
Let us explain how to transport a passenger in the following two cases.
We can transport a passenger from the island $1$ to the island $4$ as follows. The islands where the ships $1, 2, 3$ are anchored, and the numbers of security guards on the ships $1, 2, 3$ are written in this order. The numbers of security guards on the islands $1, 2, 3, 4$ are written in this order.
| # | Operation | The islands where the ships are anchored | The numbers of security guards on the ships | The numbers of security guards on the islands |
|---|---|---|---|---|
| - | - | $2, 2, 4$ | $2, 2, 3$ | $0, 0, 0, 0$ |
| $1$ | Move the ship $1$ from the island $2$ to the island $1$ | $1, 2, 4$ | $2, 2, 3$ | $0, 0, 0, 0$ |
| $2$ | Make a passenger get on the ship $1$ | $1, 2, 4$ | $2, 2, 3$ | $0, 0, 0, 0$ |
| $3$ | Move the ship $1$ from the island $1$ to the island $2$ | $2, 2, 4$ | $2, 2, 3$ | $0, 0, 0, 0$ |
| $4$ | Make one security guard and the passenger get off the ship $1$ | $2, 2, 4$ | $1, 2, 3$ | $0, 1, 0, 0$ |
| $5$ | Make one security guard and the passenger get on the ship $2$ | $2, 2, 4$ | $1, 3, 3$ | $0, 0, 0, 0$ |
| $6$ | Move the ship $2$ from the island $2$ to the island $3$ | $2, 3, 4$ | $1, 3, 3$ | $0, 0, 0, 0$ |
| $7$ | Make the passenger get off the ship $2$ | $2, 3, 4$ | $1, 3, 3$ | $0, 0, 0, 0$ |
| $8$ | Move the ship $3$ from the island $4$ to the island $3$ | $2, 3, 3$ | $1, 3, 3$ | $0, 0, 0, 0$ |
| $9$ | Make the passenger get on the ship $3$ | $2, 3, 3$ | $1, 3, 3$ | $0, 0, 0, 0$ |
| $10$ | Move the ship $3$ from the island $3$ to the island $4$ | $2, 3, 4$ | $1, 3, 3$ | $0, 0, 0, 0$ |
| $11$ | Make the passenger get off the ship $3$ | $2, 3, 4$ | $1, 3, 3$ | $0, 0, 0, 0$ |
We can transport a passenger from the island $3$ to the island $2$ as follows.
| # | Operation | The islands where the ships are anchored | The numbers of security guards on the ships | The numbers of security guards on the islands |
|---|---|---|---|---|
| - | - | $2, 2, 4$ | $2, 2, 3$ | $0, 0, 0, 0$ |
| $1$ | Make one security guard get off the ship $1$ | $2, 2, 4$ | $1, 2, 3$ | $0, 1, 0, 0$ |
| $2$ | Make one security guard get on the ship $2$ | $2, 2, 4$ | $1, 3, 3$ | $0, 0, 0, 0$ |
| $3$ | Move the ship $2$ from the island $2$ to the island $3$ | $2, 3, 4$ | $1, 3, 3$ | $0, 0, 0, 0$ |
| $4$ | Make a passenger get on the ship $2$ | $2, 3, 4$ | $1, 3, 3$ | $0, 0, 0, 0$ |
| $5$ | Move the ship $2$ from the island $3$ to the island $2$ | $2, 2, 4$ | $1, 3, 3$ | $0, 0, 0, 0$ |
| $6$ | Make the passenger get off the ship $2$ | $2, 2, 4$ | $1, 3, 3$ | $0, 0, 0, 0$ |
Since it is impossible to satisfy the conditions if the number of security guards is less than or equal to $6$, output $7$.
This sample input satisfies the constraints of Subtasks 2, 3, 4, 5, 6, 7.
4 3 1 2 1 3 2 1 2 2 3 3 4
7 5
If the number of newly introduced ships is $0$, similarly as Sample Input 1, we need $7$ security guards.
If the number of newly introduced ships is $1$, we need $5$ security guards. For example, the conditions are satisfied if we allocate the ships and $5$ security guards as follows.
This sample input satisfies the constraints of Subtasks 5, 6, 7.
3 3 0 1 1 1 1 2 1 3 2 3
2
If the number of newly introduced ships is $0$, we need $2$ security guards. For example, the conditions are satisfied if we allocate the ships and $2$ security guards as follows.
This sample input satisfies the constraints of Subtasks 4, 5, 6, 7.
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
This sample input satisfies the constraints of all the subtasks.
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
This sample input satisfies the constraints of Subtasks 3, 4, 5, 6, 7.