Find the K-th smallest travel distance among all pairs of cabins placed on a weighted tree of river regions.
Hard8Binary searchDivide and conquerTreeNo attempts yetTime limit6sMemory limit64 MBSubin and Jinyoung were camping by a mountain river when they found M cabins. The river has N regions. Region 1 sits at the lower course of the river, and the other regions sit at the middle or upper course. The M cabins stand in M different regions, one cabin per region. In the picture below, the regions painted gray are the ones with a cabin.

From every region except region 1, going down the river brings you to one other region, and the number of that region is always smaller than the number of the region you left. The current is weak, so going down the river takes the same time as going up it. The distance between two regions is the time it takes to travel along the river from one to the other.
A cabin is small, so Subin and Jinyoung cannot stay in the same one. They take two different cabins. While they get along they take the two closest cabins, but after a fight they have to move to the K-th closest pair of cabins.
List every pair of two cabins in order of distance, from the smallest, and find the distance of the K-th pair.
The first line has the number of regions N, the number of cabins M, and the relationship value K of Subin and Jinyoung.
Each of the next N−1 lines, for i=2,3,…,N in this order, has the number Ri of the region you reach by going down the river from region i, and the travel time Di of that stretch.
The last line has the cabin positions C1,C2,…,CM in increasing order. Every cabin is in a different region.
2≤M≤N≤100,000, 1≤Ri<i, 1≤Di≤10,000, 1≤K≤M(M−1)/2
Print the distance of the K-th closest pair of cabins.
If 3 pairs of cabins are at distance 2 and 2 pairs are at distance 5, then the answers for K=1,2,3,4,5 are 2, 2, 2, 5, 5 in that order.