luogu#P5021. [NOIP 2018 提高组] 赛道修建

    ID: 4032 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>贪心2018二分NOIP 提高组最近公共祖先 LCA

[NOIP 2018 提高组] 赛道修建

Problem Description

City C is going to host a series of car races. Before the races, it is necessary to build mm race tracks in the city.

City C has nn intersections, numbered 1,2,,n1,2,\ldots,n. There are n1n-1 bidirectional roads suitable for building tracks, and each road connects two intersections. The ii-th road connects intersections aia_i and bib_i, and its length is lil_i. Using these n1n-1 roads, you can reach every other intersection from any starting intersection.

A track is a sequence of pairwise distinct roads e1,e2,,eke_1,e_2,\ldots,e_k, such that you can start from some intersection, then pass through roads e1,e2,,eke_1,e_2,\ldots,e_k in order (each road is used exactly once, and turning back is not allowed), and finally arrive at another intersection. The length of a track is the sum of the lengths of all roads it passes through. For safety, each road may be used by at most one track.

The track construction plan has not been decided yet. Your task is to design a construction plan so that, among the mm tracks built, the shortest track is as long as possible (that is, maximize the minimum track length among the mm tracks).

Input Format

The first line contains two positive integers n,mn,m separated by spaces, representing the number of intersections and the number of tracks to be built.

The next n1n-1 lines each contain three positive integers ai,bi,lia_i,b_i,l_i, describing the two intersections connected by the ii-th road and the road length. It is guaranteed that any two intersections are mutually reachable via these n1n-1 roads. Adjacent numbers in each line are separated by one space.

Output Format

Output one line containing one integer, representing the maximum possible value of the minimum track length.

7 1 
1 2 10 
1 3 5 
2 4 9 
2 5 8 
3 6 6 
3 7 7
31
9 3 
1 2 6 
2 3 3 
3 4 5 
4 5 10 
6 2 4 
7 2 9 
8 4 7 
9 4 4
15

Hint

[Explanation for Sample 1]

All intersections and the roads suitable for building tracks are shown in the figure below:

The number in parentheses beside a road is the road index, and the number not in parentheses is the road length. You need to build 11 track. You can build a track that goes through roads 3,1,2,63,1,2,6 (from intersection 44 to intersection 77). Then the track length is 9+10+5+7=319 + 10 + 5 + 7 = 31, which is the maximum among all plans.

[Explanation for Sample 2]

All intersections and the roads suitable for building tracks are shown in the figure below:

You need to build 33 tracks. You can build the following 33 tracks:

  1. A track that goes through roads 1,61,6 (from intersection 11 to intersection 77), with length 6+9=156 + 9 = 15;
  2. A track that goes through roads 5,2,3,85,2,3,8 (from intersection 66 to intersection 99), with length 4+3+5+4=164 + 3 + 5 + 4 = 16;
  3. A track that goes through roads 7,47,4 (from intersection 88 to intersection 55), with length 7+10=177 + 10 = 17. The minimum track length is 1515, which is the maximum among all plans.

Constraints

The ranges and characteristics of all testdata are shown in the table below:

Test Point ID nn mm ai=1a_i=1 bi=ai+1b_i=a_i+1 Branching 3\le 3
11 5\le 5 =1=1 No No Yes
22 10\le 10 n1\le n-1 Yes
33 15\le 15 Yes No No
44 103\le 10^3 =1=1 No Yes
55 3×104\le 3\times 10^4 Yes No
66 No
77 n1\le n-1 Yes
88 5×104\le 5\times 10^4
99 103\le 10^3 No Yes Yes
1010 3×104\le 3\times 10^4
1111 5×104\le 5\times 10^4
1212 50\le 50 No
1313
1414 200\le 200
1515
1616 103\le 10^3
1717 No
1818 3×104\le 3\times 10^4
1919
2020 5×104\le 5\times 10^4

Here, “Branching 3\le 3” means that each intersection is connected to at most 33 roads.

For all data, $2 \le n \le 5\times 10^4, \ 1 \le m \le n − 1,\ 1 \le a_i,b_i \le n,\ 1 \le l_i \le 10^4$.

Input Format

The first line contains two positive integers n,mn,m separated by spaces, representing the number of intersections and the number of tracks to be built.

The next n1n-1 lines each contain three positive integers ai,bi,lia_i,b_i,l_i, describing the two intersections connected by the ii-th road and the road length. It is guaranteed that any two intersections are mutually reachable via these n1n-1 roads. Adjacent numbers in each line are separated by one space.

Output Format

Output one line containing one integer, representing the maximum possible value of the minimum track length.

Hint

Translated by ChatGPT 5