ZOJ 1655 Transport Goods

Source: Internet
Author: User

ZOJ 1655 Transport Goods

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

Well, I don't know much about it at the very beginning. I think it's a problem =. =

Later, I came to see others and typed dijkstra ,...

Dis stores the largest transport rate, so the greatest path is obtained.

# Include
 
  
# Include
  
   
# Include
   
    
# Include
    
     
Using namespace std; const int eps = 1e-6; const int maxn = 110; double dis [maxn]; double cost [maxn]; int visit [maxn]; double mp [maxn] [maxn]; int n, m; void dijkstra () {int pos; memset (visit, 0, sizeof (visit )); for (int I = 1; I <= n; I ++) dis [I] = mp [n] [I]; dis [n] = 1; visit [n] = 1; // the start point is set to the maximum for (int I = 1; I <= n; I ++) {pos =-1; for (int j = 1; j <= n; j ++) {if (! Visit [j] & (pos =-1 | dis [pos]
     
      

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.