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−1routes, 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 11to 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).
样例输入复制
-
2 2
-
1 2 2 14
-
1 2 5
-
2 1 4
样例输出复制
yareyaredawa
题目来源
模板题 博客:https://blog.csdn.net/henucm/article/details/82634462
#include<cstdio>
#include<cmath>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<map>
#include<queue>
#define N 0x3f3f3f3f
#define ll long long
using namespace std;
int n,m;
struct ac
{
int v,w,next;
}edge[200010],edge1[200010];
int head[1010],head1[1010],dis[1010],vis[1010],cnt,cnt1;
struct acc{
int v,g,f;
bool operator<(const acc &r)const
{
if(r.f==f)
return r.g<g;
return r.f<f;
}
};
void add(int u,int v,int w)
{
edge[cnt].v=v;
edge[cnt].w=w;
edge[cnt].next=head[u];
head[u]=cnt++;
}
void add1(int u,int v,int w)
{
edge1[cnt1].v=v;
edge1[cnt1].w=w;
edge1[cnt1].next=head1[u];
head1[u]=cnt1++;
}
int spfa(int x)
{
int num[1010];
for(int i=1;i<=n;i++)
{
dis[i]=N;
num[i]=0;
}
queue<int>q;
dis[x]=0;
q.push(x);
num[x]++;
while(!q.empty())
{
int u=q.front();
q.pop();
num[u]--;
if(num[u]>n)
return 0;
for(int i=head1[u];i+1;i=edge1[i].next)
{
if(dis[edge1[i].v]>dis[u]+edge1[i].w)
{
dis[edge1[i].v]=dis[u]+edge1[i].w;
if(!num[edge1[i].v])
{
num[edge1[i].v]++;
q.push(edge1[i].v);
}
}
}
}
return 1;
}
int a_star(int s,int t,int k)
{
acc e,ne;
priority_queue<acc>qq;
if(s==t)
k++;
if(dis[s]==N)
return -1;
e.v=s;
e.g=0;
e.f=e.g+dis[e.v];
qq.push(e);
int flag=0;
while(!qq.empty())
{
e=qq.top();
qq.pop();
if(e.v==t)
flag++;
if(flag==k)
return e.g;
for(int i=head[e.v];i+1;i=edge[i].next)
{
ne.v=edge[i].v;
ne.g=e.g+edge[i].w;
ne.f=ne.g+dis[ne.v];
qq.push(ne);
}
}
return -1;
}
void init()
{
memset(head,-1,sizeof(head));
memset(head1,-1,sizeof(head1));
cnt=cnt1=1;
}
int main()
{
int a,b,len,s,t,k,maxt;
while(cin>>n>>m)
{
init();
cin>>s>>t>>k>>maxt;
for(int i=0;i<m;i++)
{
cin>>a>>b>>len;
add(a,b,len);
add1(b,a,len);
}
spfa(t);
int ans=a_star(s,t,k);
if(ans==-1)
cout<<"Whitesnake!"<<endl;
else if(ans>maxt)
{
cout<<"Whitesnake!"<<endl;
}
else
cout<<"yareyaredawa"<<endl;
}
return 0;
}