ACM-ICPC 2018 沈阳赛区网络预赛 D Made In Heaven(第k短路,A*算法)
https://nanti.jisuanke.com/t/31445
题意
能否在t时间内把第k短路走完。
分析
A*算法板子。
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <algorithm>
#include <cmath>
#include <ctime>
#include <vector>
#include <queue>
#include <map>
#include <stack>
#include <set>
#include <bitset>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define ms(a, b) memset(a, b, sizeof(a))
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define eps 0.0000000001
#define IOS ios::sync_with_stdio(0);cin.tie(0);
#define random(a, b) rand()*rand()%(b-a+1)+a
#define pi acos(-1)
//const ll INF = 0x3f3f3f3f3f3f3f3fll;
const int inf = 1e9;
const int maxn = + ;
const int maxm = + ;
const int mod = ;
int head[maxn],nxt[maxm],head1[maxn],nxt1[maxm];
int dis[maxn];
bool vis[maxn];
int n,m,e,st,en,k,t;
struct note{
int u,v,c;
note(){}
note(int u,int v,int c):u(u),v(v),c(c){}
}p[maxm];
struct POJ{
int v,c;
POJ(){}
POJ(int v,int c):v(v),c(c){}
bool operator < (const POJ& other)const{
return c+dis[v]>other.c+dis[other.v];
}
};
void addnote(int u,int v,int c){
p[e]=note(u,v,c);
nxt[e]=head[u];head[u]=e;
nxt1[e]=head1[v];head1[v]=e++;
}
void dij(int src){
memset(vis,,sizeof(vis));
for(int i=;i<=n;i++) dis[i]=inf;
dis[src]=;
priority_queue<POJ> que;
que.push(POJ(src,));
while(!que.empty()){
POJ pre=que.top();que.pop();
vis[pre.v]=true;
for(int i=head1[pre.v];i+;i=nxt1[i]){
if(dis[p[i].u]>dis[pre.v]+p[i].c){
dis[p[i].u]=dis[pre.v]+p[i].c;
que.push(POJ(p[i].u,));
}
}
while(!que.empty()&&vis[que.top().v]) que.pop();
}
}
int a_star(int src){
priority_queue<POJ> que;
que.push(POJ(src,));k--;
while(!que.empty()){
POJ pre=que.top();que.pop();
if(pre.v==en){
if(k) k--;
else return pre.c;
}
for(int i=head[pre.v];i+;i=nxt[i])
if(pre.c+p[i].c<=t)
que.push(POJ(p[i].v,pre.c+p[i].c));
}
return -;
}
int main(){
#ifdef LOCAL
freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
#endif
while(~scanf("%d%d",&n,&m)){
scanf("%d%d%d%d",&st,&en,&k,&t);
memset(head,-,sizeof(head));
memset(head1,-,sizeof(head1));
e=;
for(int i=;i<m;i++){
int u,v,c;
scanf("%d%d%d",&u,&v,&c);
addnote(u,v,c);
}
dij(en);
if(dis[st]==inf){
puts("Whitesnake!");
continue;
}
// if(st==en) k++;
int ans=a_star(st);
if(ans==-||ans>t){
puts("Whitesnake!");
}else{
puts("yareyaredawa");
}
// printf("%d\n",a_star(st));
}
return ;
}
ACM-ICPC 2018 沈阳赛区网络预赛 D Made In Heaven(第k短路,A*算法)的更多相关文章
- 图上两点之间的第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 ...
- 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 沈阳赛区网络预赛-K:Supreme Number
Supreme Number A prime number (or a prime) is a natural number greater than 11 that cannot be formed ...
- 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 沈阳赛区网络预赛 J树分块
J. Ka Chang Given a rooted tree ( the root is node 11 ) of NN nodes. Initially, each node has zero p ...
- 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 ...
- ACM-ICPC 2018 沈阳赛区网络预赛 F. Fantastic Graph
"Oh, There is a bipartite graph.""Make it Fantastic." X wants to check whether a ...
随机推荐
- .NET 术语
.NET 术语 1. AOT 预编译器.与 JIT 类似,此编译器还可将 IL 转换为机器代码. 与 JIT 编译相比,AOT 编译在应用程序执行前进行并且通常在不同计算机上执行. 由于在运行时 AO ...
- 虚拟机配置Linux上网环境
概要:在虚拟机安装CentOS6.5的环境后,配置NAT模式,修改系统文件支持上网. (1)ip地址的配置,IP地址的子网掩码为255.255.255.0. (2)网关的指定,也就是默认路由,当我们需 ...
- SpringCloud 学习网址记录
SpringCloud Gateway https://www.cnblogs.com/ityouknow/p/10141740.html 熔断降级的概念 https://blog.csdn.net/ ...
- Linux删除文件夹和修改文件名
rm [选项] 文件 -f, --force 强力删除,不要求确认 -i 每删除一个文件或进入一个子目录都要求确认 -I 在删除超过三个文件或者递归删除前要求确认 -r, -R 递归删除子目录 -d, ...
- MongoDB Change Stream:简介、尝试与应用
在MongoDB3.6引入的新feature中,change stream无疑是非常吸引人的. Change streams allow applications to access real-tim ...
- js字符串转时间
function StrToDateTime(value) { if (value) { return (new Date(Date.parse(value.replace(/-/g, "/ ...
- visual studio 各版本激活码
visual studio 各版本 激活码 版本 产品型号 激活码 vs2019 Enterprise(企业版) BF8Y8-GN2QH-T84XB-QVY3B-RC4DF vs2019 Profes ...
- 【alpha阶段】第一次Scrum Meeting
每日任务内容 队员 昨日完成任务 明日要完成的任务 牛宇航 #2 数据库重构https://github.com/rRetr0Git/rateMyCourse/issues/2 #8 后端函数修正及重 ...
- DOTween坑点
Sequence相关 如实现一个物体有序列的运动,A->B->C,需要实例化Sequence与实现方法在同一处调用. Sequence m_Sequence; void SequenceM ...
- ST表
ST表的原理及其实现 ST表类似树状数组,线段树这两种算法,是一种用于解决RMQ(Range Minimum/Maximum Query,即区间最值查询)问题的离线算法 与线段树相比,预处理复杂度同为 ...