#P6594. [YsOI2020] 换寝室
[YsOI2020] 换寝室
Background
School is about to start, and Ysuperman is extremely busy assigning dorm rooms to the kids......
Problem Description
There are rooms in the kindergarten. These rooms are connected by bidirectional roads. The -th road connects rooms and . Ysuperman can choose to open or close each road. With all roads open, every room can reach any other room.
Each room has a “difference value”. The difference value of room is .
After deciding which roads to close, the whole dormitory will be split into several connected components. For a connected component, the kids’ dissatisfaction value is defined as the maximum difference value minus the minimum difference value within that component. The kids’ total dissatisfaction value is defined as the maximum dissatisfaction value among all connected components.
There are dorm teachers. Each teacher checks rooms at night. The -th teacher will walk from room to room . If a teacher passes through a closed road during the check, they will be very angry. A teacher’s dissatisfaction value is defined as the number of closed roads on the path from to . The teachers’ total dissatisfaction value is defined as the sum of dissatisfaction values of all teachers.
The maximum teachers’ total dissatisfaction value that Ysuperman can tolerate is . Now Ysuperman wants to know the minimum possible value of the kids’ total dissatisfaction value.
Input Format
The input contains lines.
The first line contains three integers , representing the number of rooms, the number of dorm teachers, and the maximum teachers’ total dissatisfaction value that Ysuperman can tolerate.
The next line contains integers. The -th integer is , representing the difference value of room .
The next lines each contain two integers. Line gives and , indicating that there is a direct road between dorms and .
The next lines each contain two integers. Line gives and , representing the -th teacher’s checking route.
Output Format
Output one integer in one line, which is the answer.
5 2 0
1 3 1 4 0
1 2
1 3
1 4
1 5
2 3
1 4
3
5 2 1
1 3 1 4 0
1 2
1 3
1 4
1 5
2 3
1 4
2
Hint
Sample Explanation
Sample Explanation

Ysuperman chooses to close the road connecting and . The teachers’ total dissatisfaction value is . The dormitory is split into connected components, and the kids’ total dissatisfaction value is .
Sample Explanation
The graph is the same as in Sample 1.
Ysuperman chooses to close the road connecting and and also the road connecting and . The teachers’ total dissatisfaction value is . The dormitory is split into connected components, and the kids’ total dissatisfaction value is .
Constraints
This problem uses bundled testdata.
| Subtask | Special Property | Score | |||
|---|---|---|---|---|---|
| 1 | None | 8 | |||
| 2 | 13 | ||||
| 3 | The tree is a chain | ||||
| 4 | The tree is a fully blooming chrysanthemum | ||||
| 5 | None | ||||
| 6 | 40 |
[A chain] is defined as: all nodes have degree .
[A fully blooming chrysanthemum] is defined as: there exists a node with degree .
For of the data, it holds that , , and .
Translated by ChatGPT 5