#P11090. [2016杭电多校]Flight
[2016杭电多校]Flight
Flight
Problem Description
You are given a tree of vertices. The query is specified by two vertices and an integer . This time, a pair of vertices is called good if the distance between them is not less than . (Here, distance between two vertices means the number of edges lying on the path between them.) In each step, you can only move between good pair of vertices. Now your task is to calculate the minimum number of steps to reach , starting from . If you can’t reach the destination, the answer is -1 for that query. A lot of queries are given to you to make this problem difficult.
Input
There are multiple test cases. The first line of the input contains an integer , the number of test cases. Each test case consists of the following lines: The first line contains three integers denoting the number of vertices, denoting the number of queries and denoting the upper bound of . The second line contains integers ,representing is a tree edge for every . The third line contains six integers $(1\leq u_1,v_1\leq N,0\leq d_1<M,10^4\leq A,B,C\leq 2\cdot 10^4$). The first query is specified by . The -th ( ) query is specified by , which are generated by the following rules:
Output
For each test case, output an integer .
Sample Input
1
6 9 5
1 2 1 3 3
6 3 0 10865 16947 15183
Sample Output
55
Author
金策工业综合大学(DPRK)
Source
2016 Multi-University Training Contest 9