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

Linear Device

Linear Device

Research Institute of Graph Handling Theory (RIGHT) needs to build a special device to support their new experiment. The scheme of this device contains three types of elements: \textit{generators}, \textit{resistors} and \textit{transistors}. Each \textbf{generator} is connected with exactly \textbf{one} other element, \textbf{resistor} is connected \textbf{two} other elements, and \textbf{transistor} is connected with \textbf{three} of them. There is also a special condition, that \textbf{no transistor is connected to another transistor}. All elements must be positioned on a metal string in such way that any two subsequent elements must be connected. Two non-subsequent elements are always allowed to be connected by an extra wire. To position all elements on a string in such a way, specialists of RIGHT invited Vasya from RIGS (Research Institute of Given Strings). But this is not a string Vasya used to deal with..., so he asked you for help. \InputFile The first line contains the number of elements in the device \textbf{N} (\textbf{2} ≤ \textbf{N} ≤ \textbf{100000}). The next \textbf{N} lines contain descriptions of elements and their connections. Each of them starts with a single letter \textbf{G}, \textbf{R} or \textbf{T} which stands for Generator, Resistor or Transistor respectively. One, two or three numbers follow, separated by spaces, indicating the numbers of elements connected with the corresponding element. Elements are enumerated from \textbf{1} to \textbf{N} in order of their description in input. Element cannot be connected to itself, and two elements are not allowed to be connected more than once. \OutputFile The only line of the output must contain \textbf{N} integer numbers - a permutation of elements that allows to position them all on a metal string such that any two consecutive elements are connected. If there is more than one solution, any solution is accepted. If there is no solution, output a single word \textbf{IMPOSSIBLE}.
Лимит времени 1 секунда
Лимит использования памяти 256 MiB
Входные данные #1
5
G 2
R 1 3
T 2 4 5
R 3 5
R 3 4
Выходные данные #1
1 2 3 5 4