Gears that touch drive each other in opposite directions at inverse radius ratios; report the reduced ratio of the last gear to the first, or a jam or no link.
Medium5GraphBFSMathNo attempts yetTime limit4sMemory limit256 MBA set of gears sits on the plane. Every gear has an integer center coordinate and an integer radius. Two gears mesh when they touch on the outside, that is, when the distance between their centers equals the sum of their radii.
Meshed gears turn in opposite directions, and the number of turns each one makes is inversely proportional to its radius. While a gear of radius r1 makes one full turn, a meshed gear of radius r2 makes r1/r2 turns.
Report what happens to the output gear when you try to turn the input gear. There are three possibilities.
If the input gear cannot move, report that result even when the input gear and the output gear are not connected.
The first line contains the number of gears n (2≤n≤1000).
Each of the next n lines contains three space-separated integers xi, yi, and ri, the center coordinate and the radius of the i-th gear (−104≤xi,yi≤104, 1≤ri≤104).
Assume the tooth count of every gear is high enough that meshed gears always engage correctly. No two gears overlap. The first gear in the list is the input gear and the last gear is the output gear.
If the input gear cannot move, print The input gear cannot move. on a single line.
If the input gear can move but is not connected to the output gear, print The input gear is not connected to the output gear. on a single line.
Otherwise print, on a single line, the ratio of the output gear's rotation to the input gear's rotation in the form ##:##, reduced to lowest terms. Write the ratio as a negative ratio when the output gear turns in the direction opposite to the input gear. For example, if the output gear turns clockwise three times while the input gear turns counterclockwise twice, print -3:2.