#P3083. [USACO13OPEN] Luxury River Cruise S
[USACO13OPEN] Luxury River Cruise S
Description
Farmer John is taking Bessie and the other cows on a cruise! They are sailing on a river network with ports (), numbered , and Bessie starts at port . Each port has exactly two outgoing rivers that lead directly to other ports, and these rivers can be traversed only in one direction.
At each port, the guide chooses to take the left river or the right river to continue downstream, and they repeat the same sequence of choices over and over. More specifically, the guide has fixed in advance a direction sequence of length (), each direction being either left or right, and then repeats this sequence times (). Please help compute the port where Bessie finally stops.
Input Format
Line : Three space-separated integers , , .
Lines to : Line contains two space-separated integers, the indices of the ports reached by taking the left and right rivers from port .
Line : space-separated characters, each either L or R. L means take the left river, and R means take the right river.
Output Format
Output a single integer, the index of the port where Bessie’s cruise ends.
4 3 3
2 4
3 1
4 2
1 3
L L R
4
Hint
In the sample, after finishing the first pass of the direction sequence, Bessie arrives at port (path: );
after the second pass, she arrives at port (path: );
finally, she ends at port (path: ).
Thanks to
Translated by ChatGPT 5
京公网安备 11011102002149号