Olympic goodies
시간 제한0.25초메모리 제한1024 MB
트리 노드에 P개의 아이템을 배치해 어떤 경로의 최대 아이템 합을 최소화하고, 그 최솟값을 구한다.
문제
Freshly arrived on the market, retailer YAOGS (Yet Another Olympic Goodies Seller) sells very expensive Olympics-themed items. To make themselves better known to the public, they halfheartedly decide to give away some of these items via a contest: the first person to answer correctly the question “How many circles are there in the Olympic Games logo?” can thus gain up to P very expensive but equally valued items.
To spice things up (and spend less), YAOGS however opts for an additional challenge, as follows. The available items are positioned along some, but possibly not all of the alleys of YAOGS’s headquarters; each alley can thus contain , , or more items. For reasons unknown, these alleys form a connected, undirected, acyclic graph (i.e., a tree) with nodes, numbered from to .
The winner knows but has no idea about either the tree structure or the items’ placement. Once goodies are placed, her task is to choose a start node and an end node . She can then collect all the items on the (unique) path from to in the tree.
YAOGS decides to cleverly place the goodies so that they minimise the maximum number of items that can possibly be collected. Assuming they properly carry out this task, what is the maximum number of items the winner can collect?
입력
Each line contains two space-separated integers. The fist line contains the numbers and . Then follow lines; the th such line contains two integers and , meaning that there is an edge between the nodes and of the tree.
출력
The output should contain a single line, consisting of a single integer: the maximum number of items that can be collected by the winner.
제한
- and for all
- the set of edges in the input file describes a valid tree structure.