Warp Drive
Time limit8sMemory limit512 MB
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.
- Level
Hard8 of 10
- Topics
- Geometry, Brute force, Math
- Solved
- No attempts yet
Problem
Warp 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.
Here is the number of flights and is the shortest possible travel time of the -th flight. The value of 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 and , a flight that departs from airport , arrives at airport and cruises at speed takes
Input
The input has at most 35 datasets, each in the following format.
n m
x1 y1
...
xn yn
a1 b1 v1
...
am bm vm
is the number of airports and is the number of flights (, ). In the next lines, and are the coordinates of airport , integers with absolute value at most 1000. In the next lines, and are the departure and the arrival airport number of the -th flight, integers between 1 and . is the cruising speed of the -th flight, that is, the distance its aircraft moves in one time unit. is given with two digits after the decimal point and satisfies .
The following hold.
- Two different airports have different coordinates.
- The departure airport and the arrival airport of every flight are different.
- Two different flights differ in the departure airport, in the arrival airport, or in both.
The end of the input is a line containing two zeros.
Output
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.