Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|

Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |

Language: Hard-working Student
Description Billy is a hard-working student. He is fond of computers and intends to learn as much as possible. Now he studies graph theory, and must write a program to build the graph which is shown on the Figure.
The vertices of the graph are labeled sequentially with integer keys starting from 0 to N - 1 (N≤10000). There are two types of edges: backward edges - labeled with B in the Figure (for example from node 4 to node 2, or from node 3 to node 1), and forward edges, labeled with F in the Figure (for example from node 1 to node 2 or from node 0 to node 3). Billy’s program starts with an initial graph that contains the vertices 0, 1, 2, 3, and must continue to build the graph based on a sequence of commands written in a text file. A command has the following specification: where index0 and index1 are the keys of vertices, and string_of_characters is a sequence of actions executed from right to left. An action is represented by one of the following characters:
where v is the array of the nodes of the graph. 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 4 <kff 0 the actions are:
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]=2 and v[3]=3. Input The file contains the sequence of commands. White spaces can occur freely in the input. The input data terminate with an end of file. Output Each print must be to the standard output from the beginning of a line. There are no empty lines in between. Sample Input 4 <kf 3 0 =bb 4 7 <ff 3 Sample Output 4 = Source |

[Submit] [Go Back] [Status] [Discuss]

All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di

Any problem, Please Contact Administrator