{"trustable":true,"sections":[{"title":"","value":{"format":"HTML","content":"\u003cdiv\u003e\u003cp\u003eThere are \u003ci\u003eN\u003c/i\u003e cities in a country, and there is one and only one simple path between each pair of cities. A merchant has chosen some paths and wants to earn as much money as possible in each path. When he move along a path, he can choose one city to buy some goods and sell them in a city after it. The goods in all cities are the same but the prices are different. Now your task is to calculate the maximum possible profit on each path. \u003c/p\u003e\u003c/div\u003e"}},{"title":"Input","value":{"format":"HTML","content":"\u003cdiv\u003e\u003cp\u003eThe first line contains \u003ci\u003eN\u003c/i\u003e, the number of cities.\u003cbr\u003eEach of the next \u003ci\u003eN\u003c/i\u003e lines contains \u003ci\u003ew\u003csub\u003ei\u003c/sub\u003e\u003c/i\u003e the goods\u0027 price in each city.\u003cbr\u003eEach of the next \u003ci\u003eN-1\u003c/i\u003e lines contains labels of two cities, describing a road between the two cities.\u003cbr\u003eThe next line contains \u003ci\u003eQ\u003c/i\u003e, the number of paths.\u003cbr\u003eEach of the next \u003ci\u003eQ\u003c/i\u003e lines contains labels of two cities, describing a path. The cities are numbered from 1 to \u003ci\u003eN\u003c/i\u003e. \u003c/p\u003e\u003cp\u003e1 ≤ \u003ci\u003eN\u003c/i\u003e, \u003ci\u003ew\u003csub\u003ei\u003c/sub\u003e\u003c/i\u003e, \u003ci\u003eQ\u003c/i\u003e ≤ 50000 \u003cbr\u003e\u003c/p\u003e\u003c/div\u003e"}},{"title":"Output","value":{"format":"HTML","content":"\u003cdiv\u003e\u003cp\u003eThe output contains \u003ci\u003eQ\u003c/i\u003e lines, each contains the maximum profit of the corresponding path. If no positive profit can be earned, output 0 instead. \u003c/p\u003e\u003c/div\u003e"}},{"title":"Sample","value":{"format":"HTML","content":"\u003ctable class\u003d\u0027vjudge_sample\u0027\u003e\n\u003cthead\u003e\n \u003ctr\u003e\n \u003cth\u003eInput\u003c/th\u003e\n \u003cth\u003eOutput\u003c/th\u003e\n \u003c/tr\u003e\n\u003c/thead\u003e\n\u003ctbody\u003e\n \u003ctr\u003e\n \u003ctd\u003e\u003cpre\u003e4\r\n1 \r\n5 \r\n3 \r\n2\r\n1 3\r\n3 2\r\n3 4\r\n9\r\n1 2\r\n1 3\r\n1 4\r\n2 3\r\n2 1\r\n2 4\r\n3 1\r\n3 2\r\n3 4\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e4\r\n2\r\n2\r\n0\r\n0\r\n0\r\n0\r\n2\r\n0\r\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n"}}]}