( You may know of a certain popular and coveted construction toy that Francis got for her birthday this week. This toy consists of a number of metal spheres that can be connected to each other using rigid links (all of the same length) with a magnet on each end. The ends of the links stick to the metal spheres, and the links can freely rotate and extend from the sphere in any direction (essentially forming a spherical joint), allowing you to create a variety of interesting structures.
Francis has assembled several such structures, and now wishes to store her creations by hanging them up in a corner of her room. She notices that, for some of her structures, when she picks it up and holds it by a single sphere, all the links collapse into a single, thin vertical line (see Figure 3) due to the pull of gravity and the spherical joints. Francis can hang up her creations by affixing one sphere on the struct ure to her ceiling, and wishes to save space by hanging each one up by the sphere that results in the shortest collapsed line. She deems those fixtures which do not hang as a single thin line to take up too much space, and discards them
Figure 3: One of Francis’s constructions (left), the same collapsed into a str aight-line fixture of length 2 (middle), and a structure that will not collapse into a single line when hung up by a ny sphere (right). Note that in the middle diagram, the horizontal gaps shown between the spheres are for i llustrative purposes only! Mathematically, the fixture would be a single, infinitely thin vertical line.
For simplicity, we can treat the metal spheres as infinitely small points and the links as line segments of unit length. Can you write a program to help Francis figure out how much space her fixtures will take, and which ones to discard? Your task is to find the shortest length possible for the collapsed fixture if you were to hang it up by a single sphere, or report that there is no way to hang up the fixture by so that it collapses into an infinitely thin straight line.
If it is not possible to hang the described fixture up by a single sphere so that it col lapses into a line, print “impossible”.
입력 6 6 1 2 5 6 3 2 3 5 4 2 4 5 출력 2 입력 4 5 1 2 2 3 3 4 1 3 2 4 출력 impossible
출처:standford/2008/