eolymp
bolt
Спробуйте наш новий інтерфейс для відправки розв'язків
Задачі

Smoking gun

Smoking gun

Andy: "\textit{Billy the Kid fired first!}" Larry: "\textit{No, I’m sure I heard the first shot coming from John!}" The arguments went back and forth during the trial after the big shoot-down, somewhere in the old wild west. Miraculously, everybody had survived (although there were serious injuries), but nobody could agree about the exact sequence of shots that had been fired. It was known that everybody had fired at most one shot, but everything had happened very fast. Determining the precise order of the shots was important for assigning guilt and penalties. But then the sheriff,Willy theWise, interrupted: "Look, I’ve got a satellite image from the time of the shooting, showing exactly where everybody was located. As it turns out, Larry was located much closer to John than to Billy the Kid, while Andy was located just slightly closer to John than to Billy the Kid. Thus, because sound travels with a finite speed of 340 meters per second, Larry may have heard John’s shot first, even if Billy the Kid fired first. But, although Andy was closer to John than to Billy the Kid, he heard Billy the Kid’s shot first -- so we know for a fact that Billy the Kid was the one who fired first! Your task is to write a program to deduce the exact sequence of shots fired in situations like the above. \InputFile On the first line a positive integer: the number of test cases, at most \textbf{100}. After that per test case: \begin{itemize} \item one line with two integers \textbf{n} (\textbf{2} ≤ \textbf{n} ≤ \textbf{100}) and \textbf{m} (\textbf{1} ≤ \textbf{m} ≤ \textbf{1000}): the number of people involved and the number of observations. \item \textbf{n} lines with a string \textbf{S}, consisting of up to \textbf{20} lower and upper case letters, and two integers \textbf{x} and \textbf{y} (\textbf{0} ≤ \textbf{x}, \textbf{y} ≤ \textbf{1000000}): the unique identifier for a person and his/her position in Cartesian coordinates, in metres from the origin. \item \textbf{m} lines of the form "\textbf{S1 heard S2 firing before S3}", where \textbf{S1}, \textbf{S2} and \textbf{S3} are identifiers among the people involved, and \textbf{S2} ≠ \textbf{S3}. \end{itemize} If a person was never mentioned as \textbf{S2} or \textbf{S3}, then it can be assumed that this person never fired, and only acted as a witness. No two persons are located in the same position. The test cases are constructed so that an error of less than \textbf{10^\{-7\}} in one distance calculation will not affect the output. \OutputFile Per test case: \begin{itemize} \item one line with the ordering of the shooters that is compatible with all of the observations, formatted as the identifiers separated by single spaces. \end{itemize} If multiple distinct orderings are possible, output "\textbf{UNKNOWN}" instead. If no ordering is compatible with the observations, output "\textbf{IMPOSSIBLE}" instead.
Ліміт часу 1 секунда
Ліміт використання пам'яті 64 MiB
Вхідні дані #1
3
4 2
BillyTheKid 0 0
Andy 10 0
John 19 0
Larry 20 0
Andy heard BillyTheKid firing before John
Larry heard John firing before BillyTheKid
2 2
Andy 0 0
Beate 0 1
Andy heard Beate firing before Andy
Beate heard Andy firing before Beate
3 1
Andy 0 0
Beate 0 1
Charles 1 3
Beate heard Andy firing before Charles
Вихідні дані #1
BillyTheKid John
IMPOSSIBLE
UNKNOWN
Джерело NWERC 2011 - The 2011 ACM Northwestern Europe Programming Contest