Assign each of n gear radii to a vertex of a connected graph so that every edge's distance equals the sum of its assigned radii, returning the lexicographically smallest assignment or impossible.
Hard8GraphMathDFSGreedyNo attempts yetTime limit2sMemory limit512 MBThe Mechanical Turk was an 18th-century fake robot that created the illusion of artificial intelligence by playing chess. It inspired us to build our own fake robot, one that creates the illusion of real intelligence by solving programming contest problems.
To make the machine look more convincing, we mounted gears on axles inside an uncovered panel. The gears are purely decorative, so we placed them to form an impressive meshing pattern without any regard for gear ratios or turning direction. It is entirely possible that none of the gears can actually turn.
It is guaranteed that every axle was connected to every other axle by meshing, either directly or indirectly. Two axles a and b have directly meshing gears when their distance equals the sum of the radii of their gears, that is, dab=rga+rgb.
Sadly, the gears fell off the machine. We believe we collected all of them, but we no longer know which gear belongs on which axle. Find a way to put the gears back on the axles so that they mesh the way they did originally.
The input consists of:
If the machine can be fixed with the given gears, output n integers g1,…,gn on one line, separated by spaces, where gi is the 1-based index of the gear to put on the i-th axle. The sequence g1,…,gn must be a permutation of 1 to n. If several valid placements exist, output the lexicographically smallest sequence g1,…,gn: at the first position where two sequences differ, the one with the smaller gear index comes first. Otherwise, output impossible.