- محدودیت زمان: ۱ ثانیه
- محدودیت حافظه: ۲۵۶ مگابایت
- Dad, I don’t have any T-shirts!
- Don’t worry son! I’m going to take a contest soon. I will bring you one.
Reza loves to participate in contests all over the country. He registers into contests for the living and not only makes his wife happy with the prize but also brings the T-shirts to his son. Obviously, Reza only participates in the contests which their transportation costs are not higher than their prize. In such cases, he will travel from Tehran to the city, takes the contest and travels back to Tehran to reward the prize and the T-shirt to his wife and son immediately. Reza’s wife wants to go shopping for the New Year soon, but she is not sure if Reza can afford the money. Help her to calculate the total money that Reza is able to earn from the contests. (Reza is an expert in ACM contests and he will win the prize in any contest he participates in)
ورودی
In the first line there will be an integer indicating the number of test cases.
Each test case begins with two integer and the number of cities hosting the contests and the number of roads between them respectively.
In the following lines, comes an integer indicating the prize of city .
The next following lines contain three integers and which means the cities and are connected to each other and the transportation cost between them is .
Assume that Reza begins from Tehran (city ) and comes back to Tehran after each contest.
خروجی
For each test case print the maximum money that Reza can earn from participating in the contest in a line
مثالها
ورودی نمونه ۱
خروجی نمونه ۱
ارسال پاسخ برای این سؤال