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 ...
随机推荐
- Linux SNMP 监控一些常用OID
Linux SNMP 监控一些常用OID ===============linux服务器snmp常用oid http://www.haiyun.me/archives/linux-snmp-oid.h ...
- BZOJ 3629 JLOI2014 聪明的燕姿 约数和+DFS
根据约数和公式来拆s,最后再把答案乘出来,我们发先这样的话递归层数不会太大每层枚举次数也不会太多,然而我们再来个剪枝就好了 #include<cstdio> #include<ios ...
- linux 条件判断式
1.利用if ...then if [ 判断条件 ];then 指令 fi 实例一 Y/N: #!/bin/bash #Program: # This program shows "Hell ...
- 湖南大学第十四届ACM程序设计新生杯 E.Easy Problem
E.Easy Problem Description: Zghh likes number, but he doesn't like writing problem description. So h ...
- bzoj 3456 城市规划 多项式求逆+分治FFT
城市规划 Time Limit: 40 Sec Memory Limit: 256 MBSubmit: 1091 Solved: 629[Submit][Status][Discuss] Desc ...
- JavaScript中cookie使用
转自:http://www.cnblogs.com/yjzhu/archive/2012/11/26/2789032.html 一.什么是 cookie? cookie 就是页面用来保存信息,比如自动 ...
- CSS3奇偶选择器
.search-form td:nth-child(odd){//奇 width:100px; text-align:right;} .search-form td:nth-child(even){/ ...
- HDU1099---数学 | 思维
hdu 1099 Lottery题意:1~n编号的彩票,要买全,等概率条件下平均要买几张.已经买了m张时,买中剩下的概率为1-m/n,则要买的张数为1/(1-m/n)n=2,s=1+1/(1-1/2) ...
- PCIe 调试
ISE 生成PCIe核之后, 在ipcore_dir目录下会产生以下文件目录 目录下包含内容如下: The doc folder contains the PCIe Endpoint Block da ...
- 【洛谷 UVA11417】 GCD(欧拉函数)
我们枚举所有gcd \(k\),求所有\(gcd=k\)的数对,记作\(f(k)\),那么\(ans=\sum_{i=1}^{n}(f(i)-1)*i\).为什么减1呢,观察题目,发现\(j=i+1\ ...