#P1730. [USACO23FEB] Fertilizing Pastures G
[USACO23FEB] Fertilizing Pastures G
题目描述
There are pastures , connected by roads, such that they form a tree. Every road takes second to cross. Each pasture starts out with grass, and the ith pasture's grass grows at a rate of units per second. Farmer John is in pasture 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 time.
The input contains an additional parameter .
- If , Farmer John must end at pasture .
- 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.
输入格式
The first line contains and .
Then for each from to , there is a line containing and , meaning that there is a road connecting pastures and . It is guaranteed that .
输出格式
The minimum amount of time and the minimum amount of fertilizer, separated by spaces.
样例 #1
样例输入 #1
5 0
1 1
1 2
3 1
3 4
样例输出 #1
8 21
样例 #2
样例输入 #2
5 1
1 1
1 2
3 1
3 4
样例输出 #2
6 29
提示
Explanation for Sample 1
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 .
This route takes time and uses fertilizer. It can be shown that is the least possible amount of time for any route that returns to node at the end and is the least possible fertilizer used for any route that returns to node and takes time.
Explanation for Sample 2
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.
This route takes time and uses fertilizer. It can be shown that is the least possible amount of time for any route and is the least possible fertilizer used for any route that takes time.
SCORING
- Inputs :
- Inputs :
- Inputs and : No pasture is adjacent to more than three roads.