图上两点之间的第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> # ...
随机推荐
- vue.js数据绑定语法
原始高清大图下载 1.数据绑定 html代码: <div id="first" class="first">msg:{{msg}}</div& ...
- MoinMoin install in apache (win)
一:下载环境 xampp:http://sourceforge.net/projects/xampp/files/XAMPP%20Windows/1.8.1/xampp-win32-1.8.1-VC9 ...
- mongodb的创建删除数据库
1.创建数据库 use 命令 MongoDB use DATABASE_NAME 用于创建数据库.该命令将创建一个新的数据库,如果它不存在,否则将返回现有的数据库. 语法: use DATABASE ...
- DataSource--DBCP--C3P0--DBUtils
一.DataSource 接口(javax.sql) 1.连接池: 由于与数据库连接的创建和销毁非常占用资源,因此提出了连接池技术,用于提升java程序操作数据库的性能;连接池 ...
- 获取cell中的button在整个屏幕上的位置
编写cell中得button点击事件 - (IBAction)showButtonClick:(id)sender { UIButton *button = (UIButton *)sender; U ...
- Linux shell标准输入,标准输出,错误输出
shell中可能经常能看到:1>/dev/null 2>&1 eg:sudo kill -9 `ps -elf |grep -v grep|grep $1|awk '{prin ...
- c/c++的const和static区别
C语言中的const和static用来修饰变量或者函数,用const修饰表示不可改变,用static修饰表示变量或者函数是静态的,作用域控制在函数内. const定义的常量在超出其作用域之后其空间会被 ...
- 在Office 365 添加就地保留用户邮箱
基于客户需求,要求将用户批量添加到Office 365中的现有就地保留.如您所了解的,我们可以通过Exchange在线图形用户GUI界面完成,也可以通过PowerShell完成. 要将用户批量添加到O ...
- SQL server的一个分割表值函数
CREATE FUNCTION [dbo].[Fn_Split] ( @SplitString text, -- 如果要传入NText类型,下面需要相应的修改,注释行为NText下同 ) = ','- ...
- HTTP错误码汇总(转)
响应码由三位十进制数字组成,它们出现在由HTTP服务器发送的响应的第一行.响应码分五种类型,由它们的第一位数字表示:1.1xx:信息,请求收到,继续处理2.2xx:成功,行为被成功地接受.理解和采纳3 ...