图上两点之间的第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. 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).
样例输入复制
2 2
1 2 2 14
1 2 5
2 1 4
样例输出复制
yareyaredawa
题目来源
//图上两点之间的第k最短路径的长度
#define P pair<int,int>
#define ph push_back
#define N 1009
#define M 10009
const int inf =0x3f3f3f3f;
int n,m,s,e,k,t;
int dis[N];
vector<P>ve[N],se[N];
void init()
{
for(int i=;i<n;i++) {
ve[i].clear();
se[i].clear();
}
}
struct Node{
int to,w;
bool operator <(const Node&a)const{
return w+dis[to]>a.w+dis[a.to];
}
};
void dijk()
{
priority_queue<P,vector<P>,greater<P> >que;
for(int i=;i<N;i++) dis[i]=inf;
dis[e]=;
que.push({,e});
while(!que.empty()){
P temp=que.top();que.pop();
int v=temp.second;
if(dis[v]<temp.first) continue;
for(int i=;i<se[v].size();i++){//反向边
P p=se[v][i];
int x=p.first,w=p.second;
if(dis[x]>dis[v]+w){
dis[x]=dis[v]+w;
que.push({dis[x],x});
}
}
}
}
int astar()
{
priority_queue<Node>que;
que.push({s,});
k--;
while(!que.empty()){
Node temp=que.top();que.pop();
int v=temp.to;
if(v==e) {
if(k) k--;
else return temp.w;
}
for(int i=;i<ve[v].size();i++){
P p=ve[v][i];
int x=p.first,w=p.second;
que.push({x,w+temp.w});
}
}
return -;
}
int main()
{
while(~scanf("%d%d",&n,&m)){
scanf("%d%d%d%d",&s,&e,&k,&t);
int u,v,w;
for(int i=;i<m;i++)
{
scanf("%d%d%d",&u,&v,&w);
ve[u].ph({v,w});
se[v].ph({u,w});
}
dijk();
if(dis[s]==inf) printf("Whitesnake!\n");
else{
if(s==e) k++;//k+1
int ans=astar();
if(ans<=t&&ans!=-) printf("yareyaredawa\n");
else{
printf("Whitesnake!\n");
}
}
}
return ;
}
图上两点之间的第k最短路径的长度 ACM-ICPC 2018 沈阳赛区网络预赛 D. Made In Heaven的更多相关文章
- ACM-ICPC 2018 沈阳赛区网络预赛 D Made In Heaven(第k短路,A*算法)
https://nanti.jisuanke.com/t/31445 题意 能否在t时间内把第k短路走完. 分析 A*算法板子. #include <iostream> #include ...
- ACM-ICPC 2018 沈阳赛区网络预赛 D. Made In Heaven(第k短路模板)
求第k短路模板 先逆向求每个点到终点的距离,再用dij算法,不会超时(虽然还没搞明白为啥... #include<iostream> #include<cstdio> #inc ...
- ACM-ICPC 2018 沈阳赛区网络预赛 D. Made In Heaven(约束第K短路)
题意:求11到nn的第kk短的路径长度,如果超过TT输出Whitesnake!Whitesnake!,否则输出yareyaredawayareyaredawa. 好无以为 , 这就是一道模板题, 当是 ...
- ACM-ICPC 2018 沈阳赛区网络预赛 K Supreme Number(规律)
https://nanti.jisuanke.com/t/31452 题意 给出一个n (2 ≤ N ≤ 10100 ),找到最接近且小于n的一个数,这个数需要满足每位上的数字构成的集合的每个非空子集 ...
- ACM-ICPC 2018 沈阳赛区网络预赛-D:Made In Heaven(K短路+A*模板)
Made In Heaven One day in the jail, F·F invites Jolyne Kujo (JOJO in brief) to play tennis with her. ...
- ACM-ICPC 2018 沈阳赛区网络预赛 F Fantastic Graph(贪心或有源汇上下界网络流)
https://nanti.jisuanke.com/t/31447 题意 一个二分图,左边N个点,右边M个点,中间K条边,问你是否可以删掉边使得所有点的度数在[L,R]之间 分析 最大流不太会.. ...
- ACM-ICPC 2018 沈阳赛区网络预赛 F. Fantastic Graph (贪心或有源汇上下界网络流)
"Oh, There is a bipartite graph.""Make it Fantastic."X wants to check whether a ...
- ACM-ICPC 2018 沈阳赛区网络预赛 F. Fantastic Graph(有源上下界最大流 模板)
关于有源上下界最大流: https://blog.csdn.net/regina8023/article/details/45815023 #include<cstdio> #includ ...
- ACM-ICPC 2018 沈阳赛区网络预赛 Made In Heaven(K短路)题解
思路:K短路裸题 代码: #include<queue> #include<cstring> #include<set> #include<map> # ...
随机推荐
- 复习KMP
KMP刚学的时候,看不懂. 再看,哇!原来是这样! 用的时候,忘了. 为了不再跌倒,我决定,记住吧... 在我看来,KMP一般用于字符串匹配时的防超时优化. 他的精髓就是,利用已经匹配的信息,简化这之 ...
- window.open()弹出窗口参数说明及居中设置
window.open()可以弹出一个新的窗口,并且通过参数控制窗口的各项属性. 最基本的弹出窗口代码 window.open('httP://codeo.cn/'); window.open()各参 ...
- 为什么要用mallloc
为什么要用malloc函数申请内存空间? 有的程序往往在运行时才知道要动态分配多大的内存,例如: void foo(char *str, int n) { char buf[?]; strncpy(b ...
- Redis相关注意事项
本文介绍了五个使用Redis使用时的注意事项.如果你在使用或者考虑使用Redis,你可以学习一下下面的一些建议,避免遇到以下提到的问题. 一.配置相关注意事项 1.涉及到内存的单位注意添加 b 1k ...
- (五)SpringMVC之使用Kaptcha实现验证码功能
一.什么是Kaptcha Kaptcha是Google开发的用于自动生成验证码的插件. 二.怎么导入Kaptcha ① 如果没有用Maven管理工具的话就直接导入包(可以直接下载:pau8) http ...
- 一把剪刀看懂git reset 和它的三个参数
都说git 命令难记且难懂,但是如果从立体的角度看待git与git管理的版本,那么一切都会明朗许多. 大多数的学习教程为了理解git,会绘制几个圆圈的串联,每个圆圈代表一个commit的版本,也就是从 ...
- Android(java)学习笔记136:利用谷歌API对数据库增删改查(推荐使用)
接下来我们通过项目案例来介绍:这个利用谷歌API对数据库增删改查 1. 首先项目图: 2. 这里的布局文件activity_main.xml: <LinearLayout xmlns:andro ...
- zend studio failed to create java virtual machine无法启动的解法
zend studio failed to create java virtual machine 解决方案:在安装目录下修改ZendStudio.ini中第十四行处改成 -Xmx512M. -sta ...
- nginx 的反向代理及缓存功能
上游服务器的设置 server { #监听的IP及端口 listen 127.0.0.1:8080; #虚拟主机对硬解析的主机名 #server_name localhost; #charset ko ...
- WINDOWS-API:关于线程CreateThread,_beginthead(_beginthreadex),AfxBeginThread
[转]windows多线程编程CreateThread,_beginthead(_beginthreadex)和AfxBeginThread的区别 在Windows的多线程编程中,创建线程的函数主要有 ...