#P89. [CSP-S 2023] Tree planting
[CSP-S 2023] Tree planting
Person in Charge
Problem Description
You are a forest caretaker. One day, you receive a task: plant trees on the plots of a forest and nurture them until they grow to specified heights.
The forest map consists of plots, with plot connected to the forest entrance. There are roads connecting these plots, ensuring that every plot is reachable from any other. Initially, no trees are planted on any plot.
Your goal is to plant one tree on each plot and ensure that the tree on the -th plot grows to a height of at least meters.
Each day, you may choose an unplanted plot that is directly adjacent (i.e., connected by a single road) to a plot with an already planted tree and plant a tree of height meters. If all plots have been planted, you perform no operation that day. Specifically, on the first day, you can only plant a tree on plot .
For each plot, starting from the day it is planted, the tree on that plot grows in height daily. Due to varying climate and soil conditions, on the -th day, the tree on the -th plot will grow by meters. Note that is counted from the first day of the entire task, not the day the tree was planted.
You want to know: what is the minimum number of days required to complete your task?
Input Format
The first line of input contains a positive integer , the number of plots in the forest.
The next lines each contain three integers , , , describing the -th plot as explained in the problem description.
The following lines each contain two positive integers , , representing a road connecting plots and .
Output Format
Output a single positive integer, the minimum number of days required to complete the task.
Samples
4
12 1 1
2 4 -1
10 3 0
7 10 -2
1 2
1 3
3 4
5
Sample 1 Explanation
Day : Plant a tree on plot . The tree on plot grows to meters.
Day : Plant a tree on plot . The trees on plots and grow to and meters, respectively.
Day : Plant a tree on plot . The trees on plots , , and grow to , , and meters, respectively.
Day : Plant a tree on plot . The trees on plots , , , and grow to , , , and meters, respectively.
Day : The trees on plots , , , and grow to , , , and meters, respectively.
Sample 2
See the files tree/tree2.in and tree/tree2.ans in the contestant directory.
Sample 3
See the files tree/tree3.in and tree/tree3.ans in the contestant directory.
Sample 4
See the files tree/tree4.in and tree/tree4.ans in the contestant directory.
Data Range
For all test data: , , , , . It is guaranteed that a solution exists within days.
| Test Case | Special Properties | |
|---|---|---|
| A | ||
| None | ||
| A | ||
| B | ||
| C | ||
| D | ||
| None |
Special Property A: For all , ;
Special Property B: For all , and ;
Special Property C: No plot is directly connected to more than roads;
Special Property D: For all , .