8231: Luxury River Cruise

内存限制:128 MB 时间限制:1 S 标准输入输出
题目类型:传统 评测方式:文本比较 上传者:
提交:31 通过:6

题目描述

农民约翰带着Bessie和奶牛在邮轮上!他们在网格上的N条河流航行(1≤N≤1000)标记为1到N,一开始他们在开始在河口1。每一个港口都有两条河流直通,直接通往其他港口,河流只能通过一条路航行。

在每一个港口,导游选择左边的河或右边的河向下航行,但他们不断重复相同的选择一遍又一遍。更具体地说,导游选择了一个m方向(1 < =m= 500),每一个向左或向右,并重复它K次(1 < = K = 1000000000)。Bessie认为她是在兜圈子,帮她找出结束的位置!

输入格式

* Line 1: Three space-separated integers N, M, and K.

* Lines 2..N+1: Line i+1 has two space-separated integers,

representing the number of the ports that port i's left and right rivers lead to, respectively.

* Line N+2: M space-separated characters, either 'L' or 'R'. 'L' represents a choice of 'left' and 'R' represents a choice of 'right'.

输出格式

* Line 1: A single integer giving the number of the port where Bessie's cruise ends.

输入样例 复制

4 3 3 
2 4 
3 1 
4 2 
1 3 
L L R 

输出样例 复制

4 

数据范围与提示

The port numbers are arranged clockwise in a circle, with 'L' being a clockwise rotation and 'R' being a counterclockwise rotation. The sequence taken is LLRLLRLLR.

After the first iteration of the sequence of directions, Bessie is at port 2 (1 -> 2 -> 3 -> 2); after the second, she is at port 3 (2 -> 3 -> 4 -> 3), and at the end she is at port 4 (3 -> 4 -> 1 -> 4).