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 N spots in the jail and M roads connecting some of the spots. JOJO finds that Pucci knows the route of the former (K−1)-th shortest path. If Pucci spots JOJO in one of these K−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 K-th quickest path to get to the destination. What's more, JOJO only has T units of time, so she needs to hurry.
JOJO starts from spot S, and the destination is numbered E. 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 T units of time.
Input
There are at most 50 test cases.
The first line contains two integers N and M (1≤N≤1000,0≤M≤10000). Stations are numbered from 1 to N.
The second line contains four numbers S,E,K and T ( 1≤S,E≤N, S≠E, 1≤K≤10000, 1≤T≤100000000 ).
Then M lines follows, each line containing three numbers U,V and W (1≤U,V≤N,1≤W≤1000) . It shows that there is a directed road from U-th spot to V-th spot with time W.
It is guaranteed that for any two spots there will be only one directed road from spot A to spot B (1≤A,B≤N,A≠B), but it is possible that both directed road <A,B> and directed road <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).
样例输入
2 2 1 2 2 14 1 2 5 2 1 4
样例输出
yareyaredawa
题目来源
A*算法求第k短路径,先预处理下以t为起点的到其它点的最短路径,而A*算法中优先队列是按w+dist[v] 从小到大排序的,dist[v]表示从t到v的距离,w表示从s到v的距离,这样第k次找到的路径就是第k短了。
1 #include <bits/stdc++.h> 2 #define ll long long 3 #define INF 0x3f3f3f3f 4 using namespace std; 5 const int N = 1e3+10; 6 const int M = 1e4+10; 7 int n, m, s, e, k, t; 8 typedef pair<int,int> P; 9 vector<P> vs[N], rvs[N]; 10 int dist[N]; 11 struct Nod{ 12 int v, w; 13 bool operator < (const Nod &a) const{ 14 return w+dist[v] > a.w+dist[a.v]; 15 } 16 }; 17 void dij() { 18 priority_queue<P, vector<P>, greater<P> >que; 19 memset(dist, INF, sizeof(dist)); 20 dist[e] = 0; 21 que.push(P(0,e)); 22 while(que.size()) { 23 P p = que.top(); que.pop(); 24 if(dist[p.second] < p.first) continue; 25 for(auto q:rvs[p.second]) { 26 int v = q.first, w = q.second; 27 if(dist[v] > dist[p.second] + w) { 28 dist[v] = dist[p.second] + w; 29 que.push(P(dist[v],v)); 30 } 31 } 32 } 33 } 34 int Astart() { 35 priority_queue<Nod> que; 36 que.push((Nod){s,0}); 37 k--; 38 while(que.size()) { 39 Nod ee = que.top(); que.pop(); 40 if(ee.v == e) { 41 if(k) k--; 42 else return ee.w; 43 } 44 for(auto E:vs[ee.v]) { 45 int u = E.first, w = E.second; 46 que.push((Nod){u,ee.w+w}); 47 } 48 } 49 return -1; 50 } 51 int main() { 52 while(scanf("%d%d", &n, &m) != EOF) { 53 scanf("%d%d%d%d",&s,&e,&k,&t); 54 for(int i = 1; i <= n; i ++) vs[i].clear(), rvs[i].clear(); 55 for(int i = 1; i <= m; i ++) { 56 int u, v, w; 57 scanf("%d%d%d", &u, &v, &w); 58 vs[u].push_back(P(v,w)); 59 rvs[v].push_back(P(u,w)); 60 } 61 dij(); 62 if(dist[s] == INF) printf("Whitesnake! "); 63 else { 64 if(s == e) k++; 65 int ans = Astart(); 66 if(ans <= t && ans != -1) printf("yareyaredawa "); 67 else printf("Whitesnake! "); 68 } 69 } 70 return 0; 71 }