#P4319. 变化的道路
变化的道路
Description
Xiao w and Xiao c are in Country H. In recent years, as Country H has developed, its roads have been constantly changing.
According to Country H’s road law, every road has a value , meaning that if Xiao w and Xiao c pass through this road, their value will decrease by . However, if Xiao w and Xiao c have already passed this road before, their value will not decrease.
Country H has cities. Initially, Country H has roads, and these roads form a tree.
Xiao w and Xiao c will start from city and visit all cities of Country H. They will travel for 32766 days in total. For each day, they want the value to still be positive after finishing the tour. Find the minimum initial they need at departure for each day.
All edges in Country H are undirected. No road connects a city to itself.
Input Format
Line 1: an integer .
Lines 2 to : each line contains three positive integers , meaning there is a road of value between cities and .
Line : an integer , meaning Country H has roads that are changing.
Lines to : each line contains integers , meaning there is a road of value from city to city , and this road exists from day to day .
Output Format
Output lines. The -th line is the minimum required on day .
4
1 3 3
3 4 4
2 4 5
3
1 2 1 1 2
2 3 8 2 3
3 4 2 1 1
7
9
13
由于版面原因,仅显示三行,接下来32763行都是13
Hint
On day 1, choose $1 \xrightarrow{1} 2 \xrightarrow{0} 1 \xrightarrow{3} 3 \xrightarrow{2} 4$. The value decreases by in total, so the minimum is .
On day 2, choose $1 \xrightarrow{1} 2 \xrightarrow{0} 1 \xrightarrow{3} 3 \xrightarrow{4} 4$. The value decreases by in total, so the minimum is .
From day 3 onward, choose $1 \xrightarrow{3} 3 \xrightarrow{4} 4 \xrightarrow{5} 2$. The value decreases by in total, so the minimum is .
Subtask 1: 15 points, , rm = 233.
Subtask 2: 15 points, , rm = 2333.
Subtask 3: 20 points, , rm = 32766, .
Subtask 4: 20 points, , rm = 32766, .
Subtask 5: 30 points, , rm = 32766.
For subtask 3, ; for other subtasks, .
Constraints for all testdata: , , .
Translated by ChatGPT 5
京公网安备 11011102002149号