#P5628. 【AFOI-19】面基

【AFOI-19】面基

Background

After lunch, a group of people planned to go check the exam venue. IY, SY, QM, MY, and UU had already agreed to meet up that afternoon. Then everyone unanimously decided to dump the responsibility of planning the trip onto IY.

(IY: ???? Why me?)

(QM: I’ll give you candy.)

(IY: Okay, no problem. Leave it to me.)

Problem Description

The city where IY lives has nn intersections, and n1n - 1 roads connect these intersections. The roads are bidirectional. In other words, the city forms a tree. The distance between two different intersections is defined as the number of roads on the simple path between them, and the distance from an intersection to itself is 00.

We also define the importance of a road. If a road becomes unusable and this causes tt pairs of intersections to be unable to reach each other, then tt is the importance of that road. As shown in the figure below:

The importance of the road between (3,4)(3,4) is 99. This is because for (1,4)(1,4), (2,4)(2,4), (3,4)(3,4), (1,5)(1,5), (2,5)(2,5), (3,5)(3,5), (1,6)(1,6), (2,6)(2,6), (3,6)(3,6) to reach each other, they all must pass through this edge.

IY received some very bad news: one intersection is under construction (but IY does not know where). The construction affects the area within distance kk from the construction point, and all intersections whose distance to the construction point is less than or equal to kk have been completely closed. This means the group cannot pass through the affected intersections or the roads directly connected to these intersections.

IY has to consider the worst case. Since he does not know the construction location, he wants to know what the maximum possible total importance of the affected roads is.

Input Format

The first line contains two integers n,kn, k.

The next n1n - 1 lines each contain two integers u,vu, v, describing a road, meaning that intersection uu is directly connected to intersection vv.

Output Format

Output one integer, representing the maximum value of the total importance of the affected roads.

6 0
1 3
3 2
5 4
3 4
4 6
19
5 1
1 2
2 3
3 4
4 5
20

Hint

  • Sample Explanation

Sample 11: This is the example shown in the statement. If the construction location is at intersection 33 or 44, then the total importance of the affected roads is 1919. No value larger than 1919 can be found.

Sample 22: It satisfies the special property of being a chain.

  • Constraints

For the first 20%20\% testdata, n100,0k7n \le 100, 0 \le k \le 7.

For the first 40%40\% of the data: the data is guaranteed to be random.

Specially, the third test point has only k==0k == 0.

For 100%100\% of the data: n30000,0k200n \le 30000, 0 \le k \le 200.

Specially, the tenth test point degenerates from a tree into a chain.

Translated by ChatGPT 5