#P8970. 宿命 | Regulation of Destiny
宿命 | Regulation of Destiny
Background
Oppression has substance. From the shell to the organs, it wraps tightly with no air getting through. Medicine is only like a drop of water squeezed into a crack, unable to put out the deep, hidden flame.
Time cannot heal everything. It only piles up the mud day after day. Her eyes have no focus. Sometimes it is as if she wakes up from a dream in shock and calls my name.
The street is a mess. Every shop is playing music. Bus tires roll over the asphalt road. Kids are fooling around. Glass bottles shatter. Electric scooters collide... but I can clearly hear my own breathing. In the rearview mirror, I once again see her unfocused stare, tears wrapping around her eyeballs, and the surface tension of the water fails with a “da” sound.
Tear open the rainy day, dive into a foreign land, and the end one longs for is heaven.
Pale blue daylight, purple clouds, weak lights embedded into the sunset.
“...Do you know? What people call power is actually the obsession in one’s heart.”
“Obsession?”
“Yeah... it’s, the things you must do, the people you must protect, you must...”
“A wish that has to come true.”
“Then... do you have such an obsession in your heart?”
“Uh... yes! My obsession is protecting my sister!”
“Silly kid. If you want to protect your sister, talk about it in your next life.”
Problem Description
Country is preparing to build a series of defensive measures to guard against an attack from Country .
Country has stellar-class battleships, and these battleships must be protected no matter what. To save materials, the commander-in-chief connected these battleships using bidirectional acceleration channels. Each battleship has two attributes , representing the battleship’s population and technology level.
On each battleship, there are two types of defensive measures you can choose from. You may build one of them, or build nothing, but you cannot build both.
Building a Type I defense on battleship costs money, and it can protect battleship itself and the battleships directly connected to it.
Building a Type II defense on battleship costs money, and it can protect battleship itself and all battleships whose distance from battleship is exactly .
The distance between battleship and battleship is defined as the minimum number of acceleration channels that need to be passed through to go from to .
Now, find the minimum amount of money required to protect all battleships.
Input Format
The first line contains two positive integers .
The next lines each contain two positive integers , indicating that the channel connects battleships and .
The next lines: the -th line contains two positive integers , representing the money needed to build a Type I defense and a Type II defense on battleship , respectively.
Output Format
One line containing one integer, the minimum amount of money required to protect all battleships.
1 1
1 1
1
3 2
1 2
1 3
2 1
111111 1111111
3 45
2
4 2
1 2
1 3
2 4
3 1
2 1
1 1
1 2
2
Hint
Sample Explanation #1
Building any type of defensive measure on battleship costs .
Sample Explanation #2
Build a Type I defense on battleship , costing .
Sample Explanation #3
Build one Type II defense on each of battleships and , costing .
Constraints
This problem uses bundled testdata and subtask dependency.
| Subtask ID | Points | ||
|---|---|---|---|
| 1 | 5 | ||
| 2 | |||
| 3 | 10 | ||
| 4 | 8 | ||
| 5 | 11 | ||
| 6 | 8 | ||
| 7 | 34 | ||
| 8 | 19 |
For of the testdata, , , , . It is guaranteed that any two battleships can reach each other through some acceleration channels.
Translated by ChatGPT 5