#P8970. 宿命 | Regulation of Destiny

    ID: 10037 远端评测题 600ms 512MiB 尝试: 0 已通过: 0 难度: 9 上传者: 标签>洛谷原创O2优化分治树形 DP洛谷月赛状压 DP

宿命 | 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 AA is preparing to build a series of defensive measures to guard against an attack from Country BB.

Country AA has nn stellar-class battleships, and these battleships must be protected no matter what. To save materials, the commander-in-chief connected these battleships using n1n - 1 bidirectional acceleration channels. Each battleship has two attributes ai,bia_i, b_i, 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 ii costs aia_i money, and it can protect battleship ii itself and the battleships directly connected to it.

Building a Type II defense on battleship ii costs bib_i money, and it can protect battleship ii itself and all battleships whose distance from battleship ii is exactly rr.

The distance between battleship uu and battleship vv is defined as the minimum number of acceleration channels that need to be passed through to go from uu to vv.

Now, find the minimum amount of money required to protect all battleships.

Input Format

The first line contains two positive integers n,rn, r.

The next n1n - 1 lines each contain two positive integers u,vu, v, indicating that the channel connects battleships uu and vv.

The next nn lines: the ii-th line contains two positive integers ai,bia_i, b_i, representing the money needed to build a Type I defense and a Type II defense on battleship ii, 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 11 costs 11.


Sample Explanation #2

Build a Type I defense on battleship 11, costing 22.


Sample Explanation #3

Build one Type II defense on each of battleships 11 and 22, costing 22.


Constraints

This problem uses bundled testdata and subtask dependency.

Subtask ID nn \le rr \le Points
1 1010 55 5
2 200200 11
3 2020 77 10
4 100100 22 8
5 44 11
6 55 8
7 200200 66 34
8 77 19

For 100%100\% of the testdata, 1n2001 \le n \le 200, 1r71 \le r \le 7, 1ai,bi1091 \le a_i, b_i \le {10}^9, 1u,vn1 \le u, v \le n. It is guaranteed that any two battleships can reach each other through some acceleration channels.

Translated by ChatGPT 5