ACM-ICPC 2018 沈阳赛区网络预赛 D. Made In Heaven(第k短路模板)
求第k短路模板
先逆向求每个点到终点的距离,再用dij算法,不会超时(虽然还没搞明白为啥。。。
#include<iostream>
#include<cstdio>
#include<cmath>
#include<queue>
#include<vector>
#include<string.h>
#include<cstring>
#include<algorithm>
#include<set>
#include<map>
#include<fstream>
#include<cstdlib>
#include<ctime>
#include<list>
#include<climits>
#include<bitset>
#include<random>
#include <ctime>
#include <cassert>
#include <complex>
#include <cstring>
#include <chrono>
using namespace std;
#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fopen freopen("input.in", "r", stdin);freopen("output.in", "w", stdout);
#define left asfdasdasdfasdfsdfasfsdfasfdas1
#define tan asfdasdasdfasdfasfdfasfsdfasfdas
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef long long ll;
typedef unsigned int un;
const int desll[][]={{,},{,-},{,},{-,}};
const int mod=1e9+;
const int maxn=1e3+;
const int maxm=1e5+;
const double eps=1e-;
int n,k,m;
int ar[maxn];
int head[maxn],sz,rehead[maxn];
bool vis[maxn];
int dis[maxn];
struct node
{
int b,nex,c;
}no[maxn*],reno[maxn*];
void add(int a,int b,int c)
{
no[sz].b=b;
no[sz].c=c;
no[sz].nex=head[a];
head[a]=sz;
reno[sz].b=a;
reno[sz].c=c;
reno[sz].nex=rehead[b];
rehead[b]=sz++;
}
struct state{
int all,pre,v;
state(int a,int b,int c){
all=a;pre=b;v=c;
}
state(){ }
bool operator<(const state& s)const{
return all>s.all;
}
};
priority_queue<state> qu;
void init(int s,int e)
{
memset(vis,,sizeof(vis));
memset(dis,-,sizeof(dis));
queue<int> qu;
qu.push(e);vis[e]=;
dis[e]=;
while(qu.size()){
int x=qu.front();
qu.pop();
vis[x]=;
for(int i=rehead[x];i!=-;i=reno[i].nex){
int v=reno[i].b;
if(dis[v]==- || dis[v]>dis[x]+reno[i].c){
dis[v]=dis[x]+reno[i].c;
if(vis[v]==){
vis[v]=;
qu.push(v);
}
}
}
}
}
int main()
{
while(scanf("%d%d",&n,&m)!=EOF){
int s,e,k,t;
scanf("%d%d%d%d",&s,&e,&k,&t);
memset(head,-,sizeof(head));
memset(rehead,-,sizeof(rehead));sz=;
for(int i=;i<m;i++){
int a,b,c;scanf("%d%d%d",&a,&b,&c);
add(a,b,c);
}
int ans=;
init(s,e);
//for(int i=1;i<=n;i++)cout<<dis[i]<<" ";cout<<endl;
if(dis[s]==-)ans=-;
else{
while(qu.size())qu.pop();
qu.push(state(dis[s],,s));
state mid;
int ins=;
while(qu.size()){
mid = qu.top();
qu.pop();
if(mid.v==e){
ins++;
if(ins==k){
ans=mid.all;
break;
}
}
for(int i=head[mid.v];i!=-;i=no[i].nex){
int v=no[i].b;
qu.push(state(mid.pre+no[i].c+dis[v],mid.pre+no[i].c,v));
}
}
}
if(ans!=- && ans<=t)printf("yareyaredawa\n");
else printf("Whitesnake!\n");
}
return ;
}
ACM-ICPC 2018 沈阳赛区网络预赛 D. Made In Heaven(第k短路模板)的更多相关文章
- 图上两点之间的第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短路,A*算法)
https://nanti.jisuanke.com/t/31445 题意 能否在t时间内把第k短路走完. 分析 A*算法板子. #include <iostream> #include ...
- 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 ...
随机推荐
- 用伪类实现一个div的宽度和高度是固定百分比
遇到一个题目:一个div宽度是固定百分比的情况下,如何设置高度是宽度的80% 看到题目的第一反应是用js控制,获取到div的宽度之后再用宽度的80%来设置div的高度,但是如何在不用js的情况下,只用 ...
- [NOIP2012] 文化之旅 dfs
这道题就体现了聪明的搜索策略的重要性,如果我们正着搜,判断效率会明显下滑,所以我们就采用倒着搜索.(其实很玄学.....) #include <cstdio> #include <b ...
- mybatis学习(七)——resultType解析
resultType是sql映射文件中定义返回值类型,返回值有基本类型,对象类型,List类型,Map类型等.现总结一下再解释 总结: resultType: 1.基本类型 :resultType= ...
- IOI1998 Polygon [区间dp]
[IOI1998]Polygon 题意翻译 题目可能有些许修改,但大意一致 多边形是一个玩家在一个有n个顶点的多边形上的游戏,如图所示,其中n=4.每个顶点用整数标记,每个边用符号+(加)或符号*(乘 ...
- word公式编辑中的转义字符
Some of the commonly used symbols: \infty - Infinity \leq - Less then or equal \geq - ...
- Windows Socket 编程_ 简单的服务器/客户端程序
转载自:http://blog.csdn.net/neicole/article/details/7459021 一.程序运行效果图 二.程序源代码 三.程序设计相关基础知识 1.计算机网络 2 ...
- Educational Codeforces Round 56 (Rated for Div. 2) ABCD
题目链接:https://codeforces.com/contest/1093 A. Dice Rolling 题意: 有一个号数为2-7的骰子,现在有一个人他想扔到几就能扔到几,现在问需要扔多少次 ...
- eclipse安装反编译插件jadclipse
下载jadClipse地址: 目的:将一些封装的jar或者sdk可以查看源代码 链接: http://pan.baidu.com/s/1kTN4TPd 提取码: 3fvd 将net.sf.jadcl ...
- 用filters定制化spring的包扫描
Fiter的信息如下: Filter的类型有:annotation(这是spring默认的),assignable,aspectj, regex,custom 首先看一下我这个demo的目录结构: 上 ...
- vsftpd主动模式和被动模式的区别
何为主动模式,何为被动模式 1.ftp采用两个端口控制: 20端口用于数据传输. 21端口用于控制,或指建立TCP连接. 2.主动方式连接过程: [注意]:C表示客户端 S表示服务器端 S端要开启20 ...