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

Трудолюбивый студент

Трудолюбивый студент

\includegraphics{https://static.e-olymp.com/content/2e/2e7adeb7eeef0f2a73cc52a42fdce2a1e4dd96c1.jpg} Билли - трудолюбивый студент. Ему очень нравятся компьютеры и он хочет узнать о них как можно больше. Сейчас он изучает теорию графов и должен написать программу, которая построит граф, изображенный на рисунке. Вершины графа последовательно пронумерованы целыми числами от \textbf{0} до \textbf{N-1} (\textbf{N} ≤ \textbf{10000}). Существует два типа ребер: обратные ребра, обозначенные буквой \textbf{B} на рисунке (например из вершины \textbf{4} в вершину \textbf{2}, или из вершины \textbf{3} в вершину \textbf{1}), и прямые ребра, обозначенные буквой \textbf{F} (например из \textbf{1} в \textbf{2} или из \textbf{0} в \textbf{3}). Программа Билли начинает работать над графом, который содержит вершины \textbf{0}, \textbf{1}, \textbf{2}, \textbf{3}. Дальше она должна строить граф согласно последовательности командaнд в текстовом файле. Каждая команда имеет следующий формат: \textit{index0 string_of_characters index1} где \textit{index0} и \textit{index1} - номера вершин, а \textit{string_of_characters} - последовательность действий, выполняемых \textbf{справа налево}. Действие описывается одним из следующих символов: \includegraphics{https://static.e-olymp.com/content/c7/c786116801ce528d111d59873ea6e3a6d726c287.jpg} где \textbf{v} - массив вершин графа. The argument of the first operation is the node v\[index1\]. The result of the operations f and b is a node that represents the argument for all the other operations. The operations < and = are the leftmost specified. For example, for the command the action are: index0 = 4, index1 = 0 x = f(v\[0\]) // forward to node 3, x = 3 y = f(x) // forward creates node (4), y = 4 k(y) // prints the key (4) V\[4\] = y // put node (4) in array v A node is put in the array v only by the command <. Initially the array contains the nodes with keys 0, 1, 2, 3, v\[0\]=0, v\[1\]=1,v\[2\]=2and v\[3\]=3. The program input is from a text file. The file contains the sequence of commands. Each print must be to the standard output from the beginning of a line. There are no empty lines in between. White spaces can occur freely in the input. The input data terminate with an end of file. An input/output sample is in the table bellow. \includegraphics{https://static.e-olymp.com/content/ec/ecccc4a70faac62de4f5cfd46fd6b538324d8cb1.jpg}
Лимит времени 1 секунда
Лимит использования памяти 64 MiB
Входные данные #1
4 <kf 3
0 =bb 4
7 <ff 3
Выходные данные #1
4
=
Источник Southeastern European Regional Programming Contest, Bucharest, Romania, October 17, 2009