eolymp
bolt
Try our new interface for solving problems
Məsələlər

Go Go Gorelians

Go Go Gorelians

The Gorelians travel through space using warp links. Travel through a warp link is instantaneous, but for safety reasons, an individual can only warp once every \textbf{10} hours. Also, the cost of creating a warp link increases directly with the linear distance between the link endpoints. The Gorelians, being the dominant force in the known universe, are often bored, so they frequently conquer new regions of space in the following manner. \begin{enumerate} \item The initial invasion force finds a suitable planet and conquers it, establishing a Regional Gorelian Galactic Government, hereafter referred to as the \textbf{RGGG}, that will govern all Gorelian matters in this region of space. \item When the next planet is conquered, a single warp link is constructed between the new planet and the \textbf{RGGG} planet. Planets connected via warp links in this manner are said to be part of the Regional Gorelian Planetary Network, that is, the \textbf{RGPN}. \item As additional planets are conquered, each new planet is connected with a single warp link to the nearest planet already in the RGPN, thus keeping the cost of connecting new planets to the network to a minimum. If two or more planets are equidistant from the new planet, the new planet is connected to whichever of them was conquered first. \end{enumerate} This causes a problem however. Since planets are conquered in a more-or-less random fashion, after a while, the \textbf{RGGG }will probably not be in an ideal location. Some Gorelians needing to consult with the \textbf{RGGG} might only have to make one or two warps, but others might require dozens - very inconvenient when one considers the \textbf{10}-hour waiting period between warps. So, once each Gorelian year, the \textbf{RGGG} analyzes the \textbf{RGPN} and relocates itself to an optimal location. The optimal location is defined as a planet that minimizes the maximum number of warps required to reach the \textbf{RGGG} from any planet in the \textbf{RGPN}. As it turns out, there is always exactly one or two such planets. When there are two, they are always directly adjacent via a warp link, and the \textbf{RGGG} divides itself evenly between the two planets. Your job is to write a program that finds the optimal planets for the \textbf{RGGG}. For the purposes of this problem, the region of space conquered by the Gorelians is defined as a cube that ranges from (\textbf{0}, \textbf{0}, \textbf{0}) to (\textbf{1000}, \textbf{1000}, \textbf{1000}). \InputFile The input consists of a set of scenarios where the Gorelians conquer a region of space. Each scenario is independent. The first line of the scenario is an integer \textbf{N} that specifies the total number of planets conquered by the Gorelians. The next \textbf{N} lines of the input specify, in the order conquered, the \textbf{ID}s and coordinates of the conquered planets to be added to the \textbf{RGPN}, in the format \textbf{ID X Y Z}. An \textbf{ID} is an integer from \textbf{1} to \textbf{1000}. \textbf{X}, \textbf{Y}, and \textbf{Z} are integers from \textbf{0} to \textbf{1000}. A single space separates the numbers. A value of \textbf{N = 0} marks the end of the input. \OutputFile For each input scenario, output the \textbf{ID}s of the optimal planet or planets where the \textbf{RGGG} should relocate. For a single planet, simply output the planet \textbf{ID}. For two planets, output the planet \textbf{ID}s, smallest \textbf{ID} first, separated by a single space.
Zaman məhdudiyyəti 1 saniyə
Yaddaşı istafadə məhdudiyyəti 64 MiB
Giriş verilənləri #1
5
1 0 0 0
2 0 0 1
3 0 0 2
4 0 0 3
5 0 0 4
5
1 0 0 0
2 1 1 0
3 3 2 0
4 2 1 0
5 3 0 0
10
21 71 76 4
97 32 5 69
70 33 19 35
3 79 81 8
31 91 17 67
52 31 48 75
48 90 14 4
41 73 2 21
83 74 41 69
26 32 30 24
0
Çıxış verilənləri #1
3
2 4
31 97
Mənbə ACM Mid-Central Regional Programming Contest 2006