3335. Ch’s gift (Hard)

单点时限: 3.0 sec

内存限制: 256 MB

Mr. Cui is working off-campus and he misses his girlfriend very much. After a whole night tossing and turning, he decides to get to his girlfriend’s city and of course, with well-chosen gifts. He knows neither too low the price could a gift be since his girlfriend won’t like it, nor too high of it since he might consider not worth to do. So he will only buy gifts with price in the range .

There are cities in the country and bi-directional roads. Each city can be reached from any other city. In the -th city, there is a specialty of price Cui could buy as a gift. Cui buys at most gift in a city. Cui starts his trip from city and his girl friend is in city . 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, buys as many as gifts as possible. Now he wants to know, how much money does he need to afford all the gifts?

输入格式

The first line contains two integers , representing the number of cities and the number of queries.

The second line contains integers , indicating the price of city ‘s specialty.

Then lines follows. Each line has two integers , meaning there is road between city and city .

line follows. In each line, there are four integers , which indicates start city, end city, lower bound of the price, upper bound of the price, respectively. There is no guarantee for the relationship between and .

输出格式

Output integers denoting the answers, respectively for queries. Use any format as you like.

样例

Input
5 3
1 2 1 3 2
1 2
2 4
3 1
2 5
4 5 1 3
1 1 1 1
3 5 2 3
Output
7 1 4

提示

This is originally a problem on HDU, but it is well-known that datasets on HDU is very weak, so that a lot of brute-force solutions got accepted. Mr. Cui is angry, as these solutions are not helpful when he is caught up with some tricky situations.

10 人解决,15 人已尝试。

43 份提交通过,共有 108 份提交。

8.9 EMB 奖励。

创建: 1 年,6 月前.

修改: 1 年前.

最后提交: 1 周,1 天前.

来源: 2017 Multi-University Training 9

题目标签