CF526G Spiders Evil Plan
Description
Spiders are Om Nom's old enemies. They love eating candies as much as he does and that's why they keep trying to keep the monster away from his favorite candies. They came up with an evil plan to trap Om Nom.
Let's consider a rope structure consisting of $ n $ nodes and $ n-1 $ ropes connecting the nodes. The structure is connected, thus, the ropes and the nodes form a tree. Each rope of the formed structure is associated with its length. A candy is tied to node $ x $ of the structure. Om Nom really wants to eat this candy.
The $ y $ spiders are trying to stop him from doing it. They decided to entangle the candy and some part of the structure into a web, thus attaching the candy to as large as possible part of the rope structure.
Each spider can use his web to cover all ropes on the path between two arbitrary nodes $ a $ and $ b $ . Thus, $ y $ spiders can cover the set of ropes which is a union of $ y $ paths in the given tree. These $ y $ paths can arbitrarily intersect each other. The spiders want the following conditions to be hold:
- the node containing the candy is adjacent to at least one rope covered with a web
- the ropes covered with the web form a connected structure (what's the idea of covering with a web the ropes that are not connected with the candy?)
- the total length of the ropes covered with web is as large as possible
The spiders haven't yet decided to what node of the structure they will tie the candy and how many spiders will cover the structure with web, so they asked you to help them. Help them calculate the optimal plan for multiple values of $ x $ and $ y $ .
Input Format
N/A
Output Format
N/A