zoj 1655 Transport Goods(dijkstra)

ZOJ Problem Set - 1655
Transport Goods
Time Limit: 1 Second      Memory Limit: 32768 KB

The HERO country is attacked by other country. The intruder is attacking the capital so other cities must send supports to the capital. There are some roads between the cities and the goods must be transported along the roads.

According the length of a road and the weight of the goods, there will be some cost during transporting. The cost rate of each road is the ratio of the cost to the weight of the goods transporting on the road. It is guaranteed that the cost rate is less than 1.

On the other hand, every city must wait till all the goods arrive, and then transport the arriving goods together with its own goods to the next city. One city can only transport the goods to one city.

Your task is find the maximum weight of goods which can arrive at the capital.


Input


There are several cases.

For each case, there are two integers N (2 <= N <= 100) and M in the first line, where N is the number of cities including the capital (the capital is marked by N, and the other cities are marked from 1 to N-1), and M is the number of roads.

Then N-1 lines follow. The i-th (1 <= i <= N - 1) line contains a positive integer (<= 5000) which represents the weight of goods which the i-th city will transport to the capital.

The following M lines represent M roads. There are three numbers A, B, and C in each line which represent that there is a road between city A and city B, and the cost rate of this road is C.

Process to the end of the file.


Output

For each case, output in one line the maximum weight which can be transported to the capital, accurate up to 2 demical places.


Sample Input

5 6
10
10
10
10
1 3 0
1 4 0
2 3 0
2 4 0
3 5 0
4 5 0


Sample Output

40.00

题意很容易明白,说是一个名字叫做HERO的国家遭到外敌侵略,需要从其他城市向首都运送物资,问最多能往首都运送多少,由于各个城市拥有的物资不一样,且在运送过程中,不同的路线会有不同的损耗,或者收费(真郁闷,都外敌侵略了,还收路费)。所以要你找出最多能往首都运多少物资。

  这题刚开始看没做出来,后来看了好多解题报告才明白,原来需要这么想:关键就是对于每一个城市的物品,最终它的消耗只与它选择的路线有关。所以先算出每个城市最多能运到首都的数量。

 

值得注意的就是要用double 用float 会wa


 


 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值