当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

6805:Deliver the Cake

题目描述
It is Zhang3's birthday! Zhang3 has bought a birthday cake and now it's time to take it home.

There are $n$ villages, labeled $1, 2, \ldots, n$. There are $m$ bidirectional roads, the $i^\mathrm{th}$ of which connects village $a_i$, $b_i$ and it is $d_i$ meter(s) long.

The bakery locates at village $s$ and Zhang3's home locates at village $t$. So Zhang3 wants to carry the cake from $s$ to $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 $x$ second(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 $s$ or $t$ is 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 \le T \le 100)$. $T$ test cases follow.

For each test case, the first line contains five integers $n, m, s, t, x \; (1 \le n \le 10^5, \; 1 \le m \le 2 \times 10^5, \; 1 \le x \le 10^9)$, 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 $i^\mathrm{th}$ character is either $\text{L}$ representing village $i$ is LEFT, or $\text{M}$ representing MIDDLE, or $\text{R}$ representing RIGHT.

Finally, $m$ lines follow, the $i^\mathrm{th}$ of which contains three integers $a_i, b_i, d_i \; (1 \le d_i \le 10^9)$, denoting a road connecting village $a_i$ and $b_i$ of length $d_i$.

It is guaranteed that $t$ can be reached from $s$.

The sum of $n$ in all test cases doesn't exceed $2 \times 10^5$. The sum of $m$ doesn't exceed $4 \times 10^5$.
输出解释
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
来自杭电HDUOJ的附加信息
Recommend liuyiding

该题目是Virtual Judge题目,来自 杭电HDUOJ

源链接: HDU-6805

最后修改于 2020-10-25T23:34:33+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
4000/2000MS(Java/Others) 524288/524288K(Java/Others)