|
||||||||||
Yaoge¡¯s maximum profitTime Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 1943 Accepted Submission(s): 625 Problem Description Yaoge likes to eat chicken chops late at night. Yaoge has eaten too many chicken chops, so that Yaoge knows the pattern in the world of chicken chops. There are N cities in the world numbered from 1 to N . There are some roads between some cities, and there is one and only one simple path between each pair of cities, i.e. the cities are connected like a tree. When Yaoge moves along a path, Yaoge can choose one city to buy ONE chicken chop and sell it in a city after the city Yaoge buy it. So Yaoge can get profit if Yaoge sell the chicken chop with higher price. Yaoge is famous in the world. AFTER Yaoge has completed one travel, the price of the chicken chop in each city on that travel path will be increased by V . Input The first line contains an integer T (0 < T ¡Ü 10), the number of test cases you need to solve. For each test case, the first line contains an integer N (0 < N ¡Ü 50000), the number of cities. For each of the next N lines, the i-th line contains an integer Wi(0 < Wi ¡Ü 10000), the price of the chicken chop in city i. Each of the next N - 1 lines contains two integers X Y (1 ¡Ü X, Y ¡Ü N ), describing a road between city X and city Y . The next line contains an integer Q(0 ¡Ü Q ¡Ü 50000), the number of queries. Each of the next Q lines contains three integer X Y V(1 ¡Ü X, Y ¡Ü N ; 0 < V ¡Ü 10000), meaning that Yaoge moves along the path from city X to city Y , and the price of the chicken chop in each city on the path will be increased by V AFTER Yaoge has completed this travel. Output For each query, output the maximum profit Yaoge can get. If no positive profit can be earned, output 0 instead. Sample Input
Sample Output
Source | ||||||||||
|