7472: Deliver the Cake

内存限制:514 MB 时间限制:2 S
题面:传统 评测方式:文本比较 上传者:
提交:35 通过:15

题目描述

It is Zhang3's birthday! Zhang3 has bought a birthday cake and now it's time to take it home.
There are nvillages, labeled 1,2,…,n. There are mbidirectional roads, the ithof which connects village ai, biand it is dimeter(s) long.
The bakery locates at village sand Zhang3's home locates at village t. So Zhang3 wants to carry the cake from sto t. She can carry the cake either with her left hand or with her right hand. She can switch to the other hand during the trip, which takes extra xsecond(s) each time (when she's performing this action, she must stay in her place). Switching is allowed at any place, including the middle of the roads. She can do this as many times as she like, or don't do it at all.
Some villages are LEFT. When Zhang3 is at a LEFT village, she must carry the cake with her left hand at the moment. In the same way, some other villages are RIGHT, she must carry with her right hand when she's at these villages. The rest villages are called MIDDLE. There's no special rules at MIDDLE villages.
Zhang3 can start and finish with any hand carrying the cake. However, if sor tis not MIDDLE, their special rules must be followed.
Please help Zhang3 find a way to take the cake home, with the minimum amount of spent time.
 

输入格式

The first line of the input gives the number of test cases, T(1≤T≤100) . T test cases follow.
For each test case, the first line contains five integers n,m,s,t,x(1≤n≤105,1≤m≤2×105,1≤x≤109) , representing the number of villages, the number of roads, the bakery's location, home's location, and the time spent for each switching.
The next line contains a string of length n , describing the type of each village. The ith character is either L representing village i is LEFT, or M representing MIDDLE, or R representing RIGHT.
Finally, m lines follow, the ith of which contains three integers ai,bi,di(1≤di≤109) , denoting a road connecting village ai and bi of length di .
It is guaranteed that t can be reached from s .
The sum of n in all test cases doesn't exceed 2×105 . The sum of m doesn't exceed 4×105 .

输出格式

For each test case, print a line with an integer, representing the minimum amount of spent time (in seconds).

输入样例 复制

1
3 3 1 3 100
LRM
1 2 10
2 3 10
1 3 100

输出样例 复制

100