#P13801. [SWERC 2023] Olympic goodies

[SWERC 2023] Olympic goodies

题目描述

:::align{center}

:::

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 half-heartedly 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 PP 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 0, 1, or more items. For reasons unknown, these alleys form a connected, undirected, acyclic graph (i.e., a tree) with NN nodes, numbered from 0 to N1N-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 N1N-1 lines; the kthk\text{th} such line contains two integers aka_k and bkb_k, meaning that there is an edge between the nodes aka_k and bkb_k of the tree.

Limits

  • 1M1000001 \leq M \leq 100000;
  • 1P1000001 \leq P \leq 100000;
  • 0akN10 \leq a_k \leq N-1 and 0bkN10 \leq b_k \leq N-1 for all kN1k \leq N-1;
  • the set of edges in the input file describes a valid tree structure.

输出格式

The output should contain a single line, consisting of a single integer: the maximum number of items that can be collected by the winner.

5 5
0 1
0 2
2 3
2 4
4

提示

Sample Explanation

For the tree in the sample input, depicted below, an optimal item placement by YAOGS guarantees that the winner cannot collect more than four items.

The figures below show two possible item placements to achieve this optimality. In the first one, the four items may be collected by choosing, for instance, nodes 11 and 33. In the second one, the four items may be collected by choosing, for instance, nodes 00 and 44.