NOIP '18 P3 - Constructing Tracks

View as PDF

Submit solution

Points: 17 (partial)
Time limit: 1.0s
Memory limit: 512M

Problem types

Given a tree with n vertices. Edge i of the tree has length l_i. We need to choose m edge-disjoint paths such that the length of the path with minimum length is maximized.

Input Specification

The first line contains two integers n and m denoting the number of vertices and the number of paths to be chosen.

In the following n-1 lines, the i^\text{th} line contains three positive integers a_i, b_i, l_i denoting the i^\text{th} edge goes from a_i to b_i and has length l_i.

Output Specification

The output contains an integer denoting the maximum possible minimum length of the m tracks chosen.

Sample Input 1

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

Sample Output 1

31

Note: the chosen path is the path from vertex 4 to vertex 7.

Sample Input 2

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

Sample Output 2

15

The chosen paths are the path from vertex 1 to vertex 7, vertex 6 to vertex 9, and vertex 8 to vertex 5.

Additional Samples

Additional samples can be found here.

Constraints

Test Case n \le m a_i = 1 b_i = a_i+1 Degree of vertex \le 3
1 5 = 1 No No Yes
2 10 \le n-1 Yes
3 15 Yes No No
4 1\,000 = 1 No Yes
5 30\,000 Yes No
6 No
7 \le n-1 Yes
8 50\,000
9 1\,000 No Yes Yes
10 30\,000
11 50\,000
12 50 No
13
14 200
15
16 1\,000
17 No
18 30\,000
19
20 50\,000

For all test cases, 2 \le n \le 50\,000, 1 \le m \le n-1, 1 \le a_i,b_i \le n, 1 \le l_i \le 10\,000.


Comments

There are no comments at the moment.