Made In Heaven

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 MM 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 AA to spot BB (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

题目来源

ACM-ICPC 2018 沈阳赛区网络预赛

题意

N个点,M条边,起始点为s,结束为n,求s到n的第k短的路的长度,判断长度是否大于T,如果大于,输出“Whitesnake!”,否则输出“yareyaredawa

这个题和POJ2449基本上一样,就多了一个和T的比较,找了模板改改就过了,点击查看模板链接。//注意输出的W是大写

AC代码

#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <limits.h>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <string>
#define ll long long
#define ull unsigned long long
#define ms(a) memset(a,0,sizeof(a))
#define pi acos(-1.0)
#define inf 0x7f7f7f7f
#define lson o<<1
#define rson o<<1|1
const double E=exp(1);
const int maxn=1e6+10;
const int mod=1e9+7;
using namespace std;
ll num1=0,num2=0,n,m,s,t,r,k,h1[maxn],h2[maxn],d[maxn],flag[maxn];
inline int read()
{
int X=0,w=1;
char c=getchar();
while (c<'0'||c>'9') { if (c=='-') w=-1; c=getchar(); }
while (c>='0'&&c<='9') X=(X<<3)+(X<<1)+c-'0',c=getchar();
return X*w;
}
struct node1
{
ll x,y,z,next;
}mp1[maxn],mp2[maxn];
struct node
{
ll v,c;
node(ll vv,ll cc) : v(vv),c(cc){}
friend bool operator < (node x,node y){return x.c+d[x.v]>y.c+d[y.v];}
};
inline void insert1(ll x,ll y,ll z)
{
mp1[++num1].x=x;
mp1[num1].y=y;
mp1[num1].z=z;
mp1[num1].next=h1[x];
h1[x]=num1;
}
inline void insert2(ll x,ll y,ll z)
{
mp2[++num2].x=x;
mp2[num2].y=y;
mp2[num2].z=z;
mp2[num2].next=h2[x];
h2[x]=num2;
}
void spfa()
{
queue<ll>Q;
Q.push(t);
for(int i=1;i<=n;i++)
d[i]=inf;
d[t]=0;
ms(flag);
flag[t]=1;
while(!Q.empty())
{
ll u=Q.front();
Q.pop();
flag[u]=0;
for(int i=h1[u];i;i=mp1[i].next)
{
ll v=mp1[i].y;
if(d[v]>d[u]+mp1[i].z)
{
d[v]=d[u]+mp1[i].z;
if(!flag[v])
{
flag[v]=1;
Q.push(v);
}
}
}
}
}
ll astar(){
if(d[s]==inf)
return -1;
priority_queue<node>p;
ll cnt=0;p.push(node(s,0));
while(!p.empty())
{
node u=p.top();p.pop();
if(u.v==t)
{
cnt++;
if(cnt==k) return u.c;
}
for(int i=h2[u.v];i;i=mp2[i].next)
{
ll y=mp2[i].y;
p.push(node(y,u.c+mp2[i].z));
}
}
return -1;
}
int main(int argc, char const *argv[])
{
while(~scanf("%lld%lld",&n,&m))
{
s=read();t=read();k=read();r=read();
ms(h1);
num1=0;
ms(h2);
num2=0;
while(m--)
{
ll x,y,z;
x=read();y=read();z=read();
insert1(y,x,z);insert2(x,y,z);
}
spfa();
ll _=astar();
if(_==-1||_>r)
printf("Whitesnake!\n");
else
printf("yareyaredawa\n");
}
return 0;
}

ACM-ICPC 2018 沈阳赛区网络预赛-D:Made In Heaven(K短路+A*模板)的更多相关文章

  1. 图上两点之间的第k最短路径的长度 ACM-ICPC 2018 沈阳赛区网络预赛 D. Made In Heaven

    131072K   One day in the jail, F·F invites Jolyne Kujo (JOJO in brief) to play tennis with her. Howe ...

  2. ACM-ICPC 2018 沈阳赛区网络预赛 D Made In Heaven(第k短路,A*算法)

    https://nanti.jisuanke.com/t/31445 题意 能否在t时间内把第k短路走完. 分析 A*算法板子. #include <iostream> #include ...

  3. ACM-ICPC 2018 沈阳赛区网络预赛 D. Made In Heaven(第k短路模板)

    求第k短路模板 先逆向求每个点到终点的距离,再用dij算法,不会超时(虽然还没搞明白为啥... #include<iostream> #include<cstdio> #inc ...

  4. ACM-ICPC 2018 沈阳赛区网络预赛 D. Made In Heaven(约束第K短路)

    题意:求11到nn的第kk短的路径长度,如果超过TT输出Whitesnake!Whitesnake!,否则输出yareyaredawayareyaredawa. 好无以为 , 这就是一道模板题, 当是 ...

  5. ACM-ICPC 2018 沈阳赛区网络预赛 K Supreme Number(规律)

    https://nanti.jisuanke.com/t/31452 题意 给出一个n (2 ≤ N ≤ 10100 ),找到最接近且小于n的一个数,这个数需要满足每位上的数字构成的集合的每个非空子集 ...

  6. ACM-ICPC 2018 沈阳赛区网络预赛-K:Supreme Number

    Supreme Number A prime number (or a prime) is a natural number greater than 11 that cannot be formed ...

  7. ACM-ICPC 2018 沈阳赛区网络预赛 J树分块

    J. Ka Chang Given a rooted tree ( the root is node 11 ) of NN nodes. Initially, each node has zero p ...

  8. ACM-ICPC 2018 沈阳赛区网络预赛 K. Supreme Number

    A prime number (or a prime) is a natural number greater than 11 that cannot be formed by multiplying ...

  9. ACM-ICPC 2018 沈阳赛区网络预赛 F. Fantastic Graph

    "Oh, There is a bipartite graph.""Make it Fantastic." X wants to check whether a ...

随机推荐

  1. absolute 导致点击事件无效

    方案一: 添加层数 z-index 方案二: 背景的透明度为0 background-color:#000; filter:alpha(opacity=0); opacity:0;

  2. valgrind 工具介绍和简单的使用

    最近老是遇上各种奇奇怪怪的core dump,不太会分析的情况下看到了这款工具.在这记录分享下. Valgrind 是个开源的工具,功能很多.例如检查内存泄漏工具---memcheck. Valgri ...

  3. Win10系列:JavaScript 项目模板和项模板

    使用Visual Studio 开发Windows应用商店应用时,通过其提供的模板可以帮助我们快速地创建一个应用.其中,在新建一个Windows应用商店应用程序项目时可以在项目模板中选择所需要的模板类 ...

  4. JSP页面间的传值方法总结

    JSP 页面间传递参数是项目中经常需要的,这应该算是 web 基本功吧.试着将各种方式总结下来,需要时可以进行权衡利弊选择最合适的方式.下面来一起看看详细的介绍: 1. URL 链接后追加参数 ? 1 ...

  5. OO Summary Ⅳ

    测试与正确性论证的效果差异 测试,或者说用断言进行黑箱测试,用大量的数据进行“覆盖性测试”,目的是当分支覆盖率达到100%也就是理论上来说所有可能的输入都已经测试过了,而输出结果均是正确的,那么我们理 ...

  6. selenium(七)expected_conditions EC

    判断一个元素是否存在,如何判断alert弹窗出来了,如何判断动态的元素等等一系列的判断,在selenium的expected_conditions模块收集了一系列的场景判断方法, 一.功能介绍和翻译 ...

  7. 类型重命名 typedef

    所谓数据重命名就是给数据类型起一个新的名字,比如int 这个数据类型,可以给他起一个新的名字叫 my int.他俩的用法.特点.属性等是一模一样,仅仅名字不同而已. 作用:1,增加代码的可读性.2,让 ...

  8. 十九. Python基础(19)--异常

    十九. Python基础(19)--异常 1 ● 捕获异常 if VS异常处理: if是预防异常出现, 异常处理是处理异常出现 异常处理一般格式: try:     <............. ...

  9. C/C++知识补充 (1)

    ● C++的圆括号运算符() 下列关于圆括号运算符的功能说法不正确的是(C) . A. 可用于强制类型转换 B 可用于类型构造 C 可用于类型声明 D 可用于函数调用 对大部分可重载的运算符来说,它既 ...

  10. 如何使用VSTO自动将Excel中的图表复制到Word

    如何使用VSTO自动将Excel中的图表复制到Word 原文地址:https://code.msdn.microsoft.com/How-to-copy-Chart-in-Excel-a29f9029 ...