|
||||||||||
Ch¡¯s giftTime Limit: 6000/3000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 3766 Accepted Submission(s): 1206 Problem Description Mr. Cui is working off-campus and he misses his girl friend very much. After a whole night tossing and turning, he decides to get to his girl friend's city and of course, with well-chosen gifts. He knows neither too low the price could a gift be since his girl friend won't like it, nor too high of it since he might consider not worth to do. So he will only buy gifts whose price is between [a,b]. There are n cities in the country and (n-1) bi-directional roads. Each city can be reached from any other city. In the ith city, there is a specialty of price ci Cui could buy as a gift. Cui buy at most 1 gift in a city. Cui starts his trip from city s and his girl friend is in city t. As mentioned above, Cui is so hurry that he will choose the quickest way to his girl friend(in other words, he won't pass a city twice) and of course, buy as many as gifts as possible. Now he wants to know, how much money does he need to prepare for all the gifts? Input There are multiple cases. For each case: The first line contains tow integers n,m(1¡Ün,m¡Ü10^5), representing the number of cities and the number of situations. The second line contains n integers c1,c2,...,cn(1¡Üci¡Ü10^9), indicating the price of city i's specialty. Then n-1 lines follows. Each line has two integers x,y(1¡Üx,y¡Ün), meaning there is road between city x and city y. Next m line follows. In each line there are four integers s,t,a,b(1¡Üs,t¡Ün;1¡Üa¡Üb¡Ü10^9), which indicates start city, end city, lower bound of the price, upper bound of the price, respectively, as the exact meaning mentioned in the description above Output Output m space-separated integers in one line, and the ith number should be the answer to the ith situation. Sample Input
Sample Output
Source | ||||||||||
|