1994: [USACO 2023 February Contest Gold] Problem 2. Fertilizing Pastures
题目描述
There are pastures (), connected by roads, such that they form a tree. Every road takes 1 second to cross. Each pasture starts out with 0 grass, and the th pasture's grass grows at a rate of () units per second. Farmer John is in pasture 1 at the start, and needs to drive around and fertilize the grass in every pasture. If he visits a pasture with units of grass, it will need amount of fertilizer. A pasture only needs to be fertilized the first time it is visited, and fertilizing a pasture takes 0 time.
The input contains an additional parameter .
- If , Farmer John must end at pasture 1.
- If , Farmer John may end at any pasture.
Compute the minimum amount of time it will take to fertilize every pasture and the minimum amount of fertilizer needed to finish in that amount of time.
输入
Then for each from to , there is a line containing and , meaning that there is a road connecting pastures and . It is guaranteed that .
输出
样例输入
5 0
1 1
1 2
3 1
3 4
样例输出
8 21
提示
The optimal route for Farmer John is as follows:
- At time , move to node , which now has grass and so needs fertilizer.
- At time , move to node , which now has grass and so needs fertilizer.
- At time , move back to node , which we already fertilized and so don't need to fertilize again.
- At time , move to node , which now has grass and so needs fertilizer.
- At time , move back to node , which we already fertilized.
- At time , move back to node .
- At time , move to node , which now has grass and so needs fertilizer.
- At time , return to node .
SAMPLE INPUT:
5 1
1 1
1 2
3 1
3 4
SAMPLE OUTPUT:
6 29
The optimal route for Farmer John is as follows:
- At time , move to node , which now has grass and so needs fertilizer.
- At time , move back to node .
- At time , move to node , which now has grass and so needs fertilizer.
- At time , move to node , which now has grass and so needs fertilizer.
- At time , move back to node , which we already fertilized and so don't need to fertilize again.
- At time , move to node , which now has grass and so needs fertilizer.
SCORING:
- Inputs 3-10:
- Inputs 11-22:
- Inputs 3-6 and 11-14: No pasture is adjacent to more than three roads.