This page is still under construction.

Parts of this page are still being built. What you see may change.

K-value

Time limit6sMemory limit256 MB

Summary
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 NN 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 LL and RR roads (both inclusive). Your task is to find the path among them which has the minimum possible kk-value.

The kk-value of a simple path is calculated as follows. Let the number of roads in the path be rr. Take the list of weights of all rr roads in the path and sort it in non-descending order. The kk-value is then the element number (⌊r/k⌋+1\lfloor r / k \rfloor + 1) of this list.

Input

The first line of input contains a single integer NN (1≤N≤1051 \le N \le 10^5). Each of the following (N−1)(N - 1) lines contains three integers aa, bb and ww which represent two cities connected by a road and the weight of the road (1≤a,b≤N1 \le a, b \le N, a≠ba \ne b, 1≤w≤1091 \le w \le 10^9).

The next line contains three integers kk, LL and RR (1<k<501 < k < 50, 1≤L≤R≤501 \le L \le R \le 50).

Output

Print the minimum possible kk-value of a path which contains between LL and RR roads, inclusive. If no such path exists, print −1-1.

Examples1

  1. Example 1

    Input
    5
    1 2 1
    2 3 2
    3 4 3
    4 5 4
    2 3 4
    
    Expected output
    2