Olympic goodies

시간 제한0.25초메모리 제한1024 MB

요약
트리 노드에 P개의 아이템을 배치해 어떤 경로의 최대 아이템 합을 최소화하고, 그 최솟값을 구한다.
난이도

보통10점 중 7점

유형
트리, DFS, 이분 탐색, 그리디
정답자
아직 제출이 없습니다

문제

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 PP available items are positioned along some, but possibly not all of the alleys of YAOGS’s headquarters; each alley can thus contain 00, 11, or more items. For reasons unknown, these alleys form a connected, undirected, acyclic graph (i.e., a tree) with NN nodes, numbered from 00 to N−1N - 1.

The winner knows NN 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 mm and an end node nn. She can then collect all the items on the (unique) path from mm to nn 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 NN and PP. Then follow N−1N - 1 lines; the kkth such line contains two integers a_ka\_k and b_kb\_k, meaning that there is an edge between the nodes a_ka\_k and b_kb\_k 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.

제한

  • 1≤N≤100,0001 \le N \le 100\\,000
  • 1≤P≤100,0001 \le P \le 100\\,000
  • 0≤a_k≤N−10 \le a\_k \le N - 1 and 0≤b_k≤N−10 \le b\_k \le N - 1 for all k≤N−1k \le N - 1
  • the set of edges in the input file describes a valid tree structure.

예제1

  1. 예제 1

    입력
    5 5
    0 1
    0 2
    2 3
    2 4
    
    예상 출력
    4