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

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

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

Zaman məhdudiyyəti 1 saniyə
Yaddaşı istafadə məhdudiyyəti 64 MiB

Билли - трудолюбивый студент. Ему очень нравятся компьютеры и он хочет узнать о них как можно больше. Сейчас он изучает теорию графов и должен написать программу, которая построит граф, изображенный на рисунке.

Вершины графа последовательно пронумерованы целыми числами от 0 до N-1 (N10000). Существует два типа ребер: обратные ребра, обозначенные буквой B на рисунке (например из вершины 4 в вершину 2, или из вершины 3 в вершину 1), и прямые ребра, обозначенные буквой F (например из 1 в 2 или из 0 в 3). Программа Билли начинает работать над графом, который содержит вершины 0, 1, 2, 3. Дальше она должна строить граф согласно последовательности командaнд в текстовом файле. Каждая команда имеет следующий формат:

index0 string_of_characters index1

где index0 и index1 - номера вершин, а string_of_characters - последовательность действий, выполняемых справа налево. Действие описывается одним из следующих символов:

где 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.

Nümunə

Giriş verilənləri #1
4 <kf 3
0 =bb 4
7 <ff 3
Çıxış verilənləri #1
4
=
Mənbə Southeastern European Regional Programming Contest, Bucharest, Romania, October 17, 2009