编程介的小学生 2017-08-19 15:42 采纳率: 20.5%
浏览 573
已采纳

Traveler Nobita

One day, Nobita used a time machine and went back to 1000 AD. He found that there are N cities in the kingdom he lived. The cities are numbered from 0 to N - 1. Before 1000 AD., there are no roads between any two cities. The kingdom will build one road between two cities at the beginning of each year starting from 1000 AD. There might be duplicated roads between two cities being built by the kingdom. You can assume that building a road takes no time.

At the beginning of every year, after the new road is built, Nobita will try to make a schedule to travel around all cities within that year. The travel should both begin at and end at the capital city - city0. Every time Nobita arrived at a city i, he will spent t1i days in that city, regardless of how many times he had come to the city. Of course he wouldn't need to spend any time in the capital city (that is to say, t10 is always 0). And t2i hours is required to pass road #i. Note that to pass each road, a passport of that road is required. And the kingdom limits that one person can only have no more than N - 1 passports of roads each year.

You are given information about the roads built in M years. Please find out the minimum time Nobita needed to complete his traveling schedule.

Input

There are multiple cases. The first line of a test case contains two integers, N (2 ≤ N ≤ 200) and M (1 ≤ M ≤ 10000). The next line contains N integers, indicating t10 ... t1n - 1. (0 ≤ t1i ≤ 50) The next M lines, the ith (0 ≤ i < M) line of this section contains three integers, ui, vi, t2i, (0 ≤ ui, vi < N; 0 ≤ t2i ≤ 5000), indicating that in year 1000 + i AD., a road will be built between city ui and city vi. t1i and t2i have been described above.

Output

For each case, you should output M lines. For the ith line, if Nobita can make a schedule in year 1000 + i, output the minimal days he can finish that schedule, rounded to two decimal digits. Otherwise output -1. There should be a blank line after each case.

Sample Input

5 6
0 5 2 5 4
0 1 1
0 2 2
0 3 5
3 4 2
2 4 4
1 2 1
Sample Output

-1
-1
-1
21.83
19.00
19.00

  • 写回答

1条回答

  • threenewbee 2017-08-29 16:52
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大