Made In Heaven
- 14.67%
- 1000ms
- 131072K
One day in the jail, F·F invites Jolyne Kujo (JOJO in brief) to play tennis with her. However, Pucci the father somehow knows it and wants to stop her. There are NN spots in the jail and MM roads connecting some of the spots. JOJO finds that Pucci knows the route of the former (K-1)(K−1)-th shortest path. If Pucci spots JOJO in one of these K-1K−1 routes, Pucci will use his stand Whitesnake and put the disk into JOJO’s body, which means JOJO won’t be able to make it to the destination. So, JOJO needs to take the KK-th quickest path to get to the destination. What’s more, JOJO only has TT units of time, so she needs to hurry.
JOJO starts from spot SS, and the destination is numbered EE. It is possible that JOJO’s path contains any spot more than one time. Please tell JOJO whether she can make arrive at the destination using no more than TT units of time.
Input
There are at most 5050 test cases.
The first line contains two integers NN and MM (1 \leq N \leq 1000, 0 \leq M \leq 10000)(1≤N≤1000,0≤M≤10000). Stations are numbered from 11 to NN.
The second line contains four numbers S, E, KS,E,K and TT ( 1 \leq S,E \leq N1≤S,E≤N, S \neq ES≠E, 1 \leq K \leq 100001≤K≤10000, 1 \leq T \leq 1000000001≤T≤100000000 ).
Then MM lines follows, each line containing three numbers U, VU,V and WW (1 \leq U,V \leq N, 1 \leq W \leq 1000)(1≤U,V≤N,1≤W≤1000) . It shows that there is a directed road from UU-th spot to VV-th spot with time WW.
It is guaranteed that for any two spots there will be only one directed road from spot AA to spot BB (1 \leq A,B \leq N, A \neq B)(1≤A,B≤N,A≠B), but it is possible that both directed road <A,B><A,B>and directed road <B,A><B,A> exist.
All the test cases are generated randomly.
Output
One line containing a sentence. If it is possible for JOJO to arrive at the destination in time, output "yareyaredawa"
(without quote), else output "Whitesnake!"
(without quote).
样例输入复制
1 | 2 2 |
样例输出复制
1 | yareyaredawa |
题目来源
题意
N个点,M条边,起始点为s,结束为n,求s到n的第k短的路的长度,判断长度是否大于T,如果大于,输出“Whitesnake!
”,否则输出“yareyaredawa
”
类似POJ2449
题解
A*+SPFA
A*算法:
1 | A*,启发式搜索,是一种较为有效的搜索方法。 |
估价函数:
1 | 为了提高搜索效率,我们可以对未来可能产生的代价进行预估。我们设计一个估价函数,以任意状态输入,计算出从该状态到目标状态所需代价的估计值。 |
第K短路:
1 | 根据估价函数的设计准则,在第K短路中从x到T的估计距离f(x)应该不大于第K短路中从x到T的实际距离g(x),于是,我们可以把估价函数f(x)定为从x到T的最短路径长度,这样不但能保证f(x)<=g(x),还能顺应g(x)的实际变化趋势。 |
代码
1 | #include<iostream> |
k短路模板
1 | const ll maxn=100010; |