设为首页 加入收藏

TOP

zoj 1655 Transport Goods (最短路变形)
2015-07-20 17:51:18 来源: 作者: 【 】 浏览:2
Tags:zoj 1655 Transport Goods 短路 变形

?

Transport Goods

Time Limit: 2 Seconds Memory Limit: 65536 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

?

货物在每条路都有一定比率的损耗,求损耗率比较低的路径即可

?

?

#include"stdio.h"
#include"string.h"
#include"iostream"
#include"algorithm"
using namespace std;
#define N 105
const int inf=-1;
double g[N][N],dis[N];
int w[N],mark[N];
double max(double a,double b)
{
    return a>b?a:b;
}
void dijkstra(int n)
{
    int i,s=n;
    double min;
    for(i=1;i<=n;i++)
        dis[i]=g[s][i];
    memset(mark,0,sizeof(mark));
    mark[s]=1;
    while(1)
    {
        min=inf;
        for(i=1;i<=n;i++)
        {
            if(!mark[i]&&min
  
   

?

?

?

?

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇Codeforces 460C 下一篇Codeforces Round #262 (Div. 2)

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·C++ 语言社区-CSDN社 (2025-12-24 17:48:24)
·CSDN问答专区社区-CS (2025-12-24 17:48:22)
·C++中`a = b = c`与` (2025-12-24 17:48:19)
·C语言结构体怎么直接 (2025-12-24 17:19:44)
·为什么指针作为c语言 (2025-12-24 17:19:41)