1751: PhoneNetwork

内存限制:128 MB 时间限制:3.000 S
评测方式:文本比较 命题人:
提交:0 解决:0

题目描述

We want to build a new phone network between N points. A number of possible cables is available to construct the network. Each of the cables connects two of the points and has an associated quality and cost. We want to select a number of these cables such that: 1) All the points are connected to each other, either directly or via other points. and 2) The quality/cost ratio (i.e., the sum of the qualities divided by the sum of the costs) is as high as possible.

输入

There are several test cases.Each case have two parts,The first parts contains two integers N,P,N is the number of the points,P is the number of the cables. The second parts,contains P lines,Each line have four integers A,B,Q,C,which means A is connected to B with a cables quality of which is Q and cost C. 2<=N<=50,0<=P<=50,1<=Q,C<=100,000

输出

For each test case output the highest quality/cost ratio,If it is impossible to connect all the points,output -1.00000000.(each test case a line) The outputs should contains 8 bit after the point.

样例输入 复制

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

样例输出 复制

1.40000000
-1.00000000
0.70588235

来源/分类