K-value
Time limit6sMemory limit256 MB
Given a weighted tree, find the minimum k-value among simple paths with between L and R edges, where the k-value is the element at rank floor(r/k)+1 of the sorted edge weights.
- Level
Hard8 of 10
- Topics
- Binary search, Tree, DFS, Greedy
- Solved
- No attempts yet
Problem
There is a country with cities. All these cities are connected by weighted roads such that there is exactly one simple route between any two cities.
Consider all simple paths which contain between and roads (both inclusive). Your task is to find the path among them which has the minimum possible -value.
The -value of a simple path is calculated as follows. Let the number of roads in the path be . Take the list of weights of all roads in the path and sort it in non-descending order. The -value is then the element number () of this list.
Input
The first line of input contains a single integer (). Each of the following lines contains three integers , and which represent two cities connected by a road and the weight of the road (, , ).
The next line contains three integers , and (, ).
Output
Print the minimum possible -value of a path which contains between and roads, inclusive. If no such path exists, print .