Place two warp points on the plane to minimize the root mean square of flight times, where each time is min(direct, dist to nearest warp) divided by speed.
Hard8GeometryBrute forceMathNo attempts yetTime limit8sMemory limit512 MBWarp drive technology is changing air travel. An aircraft that reaches the airspace above a warp field built on the ground is transferred to its destination in an instant.
With the current technology a warp field is expensive, and the budget covers only two of them. The cost does not depend on the location, so you may build them anywhere on the ground, including on an airport.
You are given the locations of the airports and a list of one way flights between them. Find where to build the two warp fields so that the average cost is as small as possible, and report that average cost. The average cost is the root mean square of the travel times of all the flights.
m1∑j=1mtj2
Here m is the number of flights and tj is the shortest possible travel time of the j-th flight. The value of tj depends on where the warp fields are.
To keep the model simple, the ground is a flat plane, and airports, aircraft and warp fields are points on that plane. Different flights use different aircraft, so their cruising speeds may differ. The time needed to climb, accelerate, decelerate and descend is 0. Once an aircraft reaches the airspace above a warp field, the time it needs after that to reach its destination is 0. Airport coordinates are integers, but warp field coordinates do not have to be.
So if the warp fields are placed at P and Q, a flight that departs from airport A, arrives at airport B and cruises at speed v takes
t=vmin(∣AB∣,∣AP∣,∣AQ∣)
The input has at most 35 datasets, each in the following format.
n m
x1 y1
...
xn yn
a1 b1 v1
...
am bm vm
n is the number of airports and m is the number of flights (2≤n≤20, 2≤m≤40). In the next n lines, xi and yi are the coordinates of airport i, integers with absolute value at most 1000. In the next m lines, aj and bj are the departure and the arrival airport number of the j-th flight, integers between 1 and n. vj is the cruising speed of the j-th flight, that is, the distance its aircraft moves in one time unit. vj is given with two digits after the decimal point and satisfies 1≤vj≤10.
The following hold.
The end of the input is a line containing two zeros.
For each dataset, print the average cost obtained by placing the two warp fields optimally, one value per line. Round the value to exactly 6 digits after the decimal point.