#P10602. [CEOI 2009] Harbingers
[CEOI 2009] Harbingers
Problem Description
Given a tree, each node has a postman. Each postman must move along the unique path to the capital (node ). Whenever he reaches a city, he has two choices:
- Continue to the next city.
- Let the postman of this city depart in his place.
Each postman needs a preparation time before departing, and has speed , meaning how many minutes it takes to walk kilometer. Now you need to find, for each city, the minimum time for that city’s postman to reach the capital (not necessarily by himself reaching the capital; someone else may reach it for him).
Input Format
The first line contains a positive integer .
The next lines each contain three positive integers , indicating that there is an edge of length between nodes and .
The next lines each contain two integers .
Output Format
Output the minimum time for the postman of each city to reach the capital.
5
1 2 20
2 3 12
2 4 1
4 5 3
26 9
1 10
500 2
2 30
206 321 542 328
Hint
For of the testdata, .
For of the testdata, the tree is a chain.
For all testdata, , , and each edge length does not exceed .
Translated by ChatGPT 5