#P2903. Hay Baler Power Train
Hay Baler Power Train
Hay Baler Power Train
Farmer John has purchased the world's most loathsome hay baler. Instead of a conventional design with a drive roller and an idler roller driving the power take-off, the machine has N rollers which drive and are driven by each other. The data for each roller is given as follows:
- \(X_i, Y_i\): The center of the roller, with \(-5000\le X_i\le5000\) and \(-5000\le Y_i\le5000\).
- \(R_i\): The roller's radius, with \(3\le R_i\le800\).
The drive roller is always located at \((0,0)\) and rotates clockwise at \(10\,000\) revolutions per hour (rph). The baler power take-off is located at \((X_t,Y_t)\), which is provided in the input. All rollers, except the drive roller, are driven by exactly one other roller, and power is never transferred from more than one roller to the same roller.
Two rollers are considered to be in contact (and thereby capable of transferring power) if the distance between their centers equals the sum of their radii, i.e. \[ \sqrt{(X_i-X_j)^2+(Y_i-Y_j)^2}=R_i+R_j. \]
If a roller of radius \(R_d\) turning at \(S\) rph drives another roller of radius \(R_x\), then the second roller turns at \[ -S\cdot\frac{R_d}{R_x} \] (recall that the negative sign denotes a reversal in the direction of rotation). The power-train is the unique chain of rollers connected from the drive roller at \((0,0)\) to the power take-off roller at \((X_t,Y_t)\). Your task is to determine this chain and output the sum of the absolute values of the speeds of all rollers in the chain. Report your answer as an integer after truncation.
Input Constraints:
- 2 \(\le N \le 1050\)
- \(-5000 \le X_i, Y_i \le 5000\)
- \(3 \le R_i \le 800\)
inputFormat
The first line of input contains three space-separated integers: \(N\), \(X_t\), and \(Y_t\), where \(N\) is the number of rollers (including the drive roller located at \((0,0)\)) and \((X_t,Y_t)\) is the position of the power take-off roller.
The following \(N\) lines each contain three integers: \(X_i\), \(Y_i\), and \(R_i\), representing the center coordinates and radius of the \(i^{th}\) roller. It is guaranteed that one of these rollers is at \((0,0)\) (the drive roller) and one is at \((X_t,Y_t)\) (the power take-off roller). Additionally, any two rollers that transfer power are externally tangent; that is, the distance between their centers is exactly \(R_i+R_j\).
outputFormat
Output a single integer: the truncated sum of the absolute values of the speeds (in revolutions per hour) of all rollers in the power train from the drive roller to the power take-off roller.
sample
2 20 0
0 0 10
20 0 10
20000