bzoj千题计划226:bzoj2763: [JLOI2011]飞行路线
http://www.lydsy.com/JudgeOnline/problem.php?id=2763
这也算分层图最短路?
dp[i][j]到城市i,还剩k次免费次数的最短路
#include<queue>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm> using namespace std; #define N 10001
#define M 50001 int n,k;
int S,T; int tot;
int front[N],nxt[M<<],to[M<<],val[M<<]; int dp[N][];
bool vis[N][]; struct node
{
int pos,rest;
int dis; node(int Pos=,int Rest=,int Dis=):pos(Pos),rest(Rest),dis(Dis){} bool operator < (node p) const
{
return dis>p.dis;
}
}now;
priority_queue<node>q; void read(int &x)
{
x=; char c=getchar();
while(!isdigit(c)) c=getchar();
while(isdigit(c)) { x=x*+c-''; c=getchar(); }
} void add(int u,int v,int w)
{
to[++tot]=v; nxt[tot]=front[u]; front[u]=tot; val[tot]=w;
to[++tot]=u; nxt[tot]=front[v]; front[v]=tot; val[tot]=w;
} void dijkstra()
{
memset(dp,,sizeof(dp));
dp[S][k]=;
now.pos=S;
now.rest=k;
q.push(now);
int u,v,cnt;
while(!q.empty())
{
now=q.top();
q.pop();
u=now.pos;
cnt=now.rest;
if(vis[u][cnt]) continue;
vis[u][cnt]=true;
for(int i=front[u];i;i=nxt[i])
{
v=to[i];
if(dp[u][cnt]+val[i]<dp[v][cnt])
{
dp[v][cnt]=dp[u][cnt]+val[i];
q.push(node(v,cnt,dp[v][cnt]));
}
if(cnt && dp[u][cnt]<dp[v][cnt-])
{
dp[v][cnt-]=dp[u][cnt];
q.push(node(v,cnt-,dp[v][cnt-]));
}
}
}
} int main()
{
int m;
read(n); read(m); read(k);
read(S); read(T);
int u,v,w;
while(m--)
{
read(u); read(v); read(w);
add(u,v,w);
}
dijkstra();
int ans=1e9;
for(int i=;i<=k;++i) ans=min(ans,dp[T][i]);
printf("%d",ans);
}
2763: [JLOI2011]飞行路线
Time Limit: 10 Sec Memory Limit: 128 MB
Submit: 3831 Solved: 1460
[Submit][Status][Discuss]
Description
Input
Output
Sample Input
0 4
0 1 5
1 2 5
2 3 5
3 4 5
2 3 3
0 2 100
Sample Output
HINT
对于30%的数据,2<=n<=50,1<=m<=300,k=0;
对于50%的数据,2<=n<=600,1<=m<=6000,0<=k<=1;
对于100%的数据,2<=n<=10000,1<=m<=50000,0<=k<=10.
bzoj千题计划226:bzoj2763: [JLOI2011]飞行路线的更多相关文章
- bzoj千题计划300:bzoj4823: [Cqoi2017]老C的方块
http://www.lydsy.com/JudgeOnline/problem.php?id=4823 讨厌的形状就是四联通图 且左右各连一个方块 那么破坏所有满足条件的四联通就好了 按上图方式染色 ...
- bzoj千题计划196:bzoj4826: [Hnoi2017]影魔
http://www.lydsy.com/JudgeOnline/problem.php?id=4826 吐槽一下bzoj这道题的排版是真丑... 我还是粘洛谷的题面吧... 提供p1的攻击力:i,j ...
- bzoj千题计划280:bzoj4592: [Shoi2015]脑洞治疗仪
http://www.lydsy.com/JudgeOnline/problem.php?id=4592 注意操作1 先挖再补,就是补的范围可以包含挖的范围 SHOI2015 的题 略水啊(逃) #i ...
- bzoj千题计划177:bzoj1858: [Scoi2010]序列操作
http://www.lydsy.com/JudgeOnline/problem.php?id=1858 2018 自己写的第1题,一遍过 ^_^ 元旦快乐 #include<cstdio> ...
- bzoj千题计划317:bzoj4650: [Noi2016]优秀的拆分(后缀数组+差分)
https://www.lydsy.com/JudgeOnline/problem.php?id=4650 如果能够预处理出 suf[i] 以i结尾的形式为AA的子串个数 pre[i] 以i开头的形式 ...
- bzoj千题计划304:bzoj3676: [Apio2014]回文串(回文自动机)
https://www.lydsy.com/JudgeOnline/problem.php?id=3676 回文自动机模板题 4年前的APIO如今竟沦为模板,,,╮(╯▽╰)╭,唉 #include& ...
- bzoj千题计划292:bzoj2244: [SDOI2011]拦截导弹
http://www.lydsy.com/JudgeOnline/problem.php?id=2244 每枚导弹成功拦截的概率 = 包含它的最长上升子序列个数/最长上升子序列总个数 pre_len ...
- bzoj千题计划278:bzoj4590: [Shoi2015]自动刷题机
http://www.lydsy.com/JudgeOnline/problem.php?id=4590 二分 这么道水题 没long long WA了两发,没判-1WA了一发,二分写错WA了一发 最 ...
- bzoj千题计划250:bzoj3670: [Noi2014]动物园
http://www.lydsy.com/JudgeOnline/problem.php?id=3670 法一:KMP+st表 抽离nxt数组,构成一棵树 若nxt[i]=j,则i作为j的子节点 那么 ...
随机推荐
- 在 Azure 上部署 Asp.NET Core Web App
在云计算大行其道的时代,当你要部署一个网站时第一选择肯定是各式各样的云端服务.那么究竟使用什么样的云端服务才能够以最快捷的方式部署一个 ASP.NET Core的网站呢?Azure 的 Web App ...
- Azure 基础:Queue Storage
Azure Storage 是微软 Azure 云提供的云端存储解决方案,当前支持的存储类型有 Blob.Queue.File 和 Table. 笔者在前文中介绍了 File Storage 的基本用 ...
- Muduo学习笔记(一) 什么都不做的EventLoop
Muduo学习笔记(一) 什么都不做的EventLoop EventLoop EventLoop的基本接口包括构造.析构.loop(). One Loop Per Thread 一个线程只有一个Eve ...
- 《Linux内核分析》第二周学习报告
<Linux内核分析>第二周学习报告 ——操作系统是如何工作的 姓名:王玮怡 学号:20135116 第一节 函数调用堆栈 一.三个法宝 二.深入理解函数调用堆栈 三.参数传递与局部变量 ...
- 《Linux内核设计与实现》 第三周 读书笔记
第一章 Linux内核简介 1. Unix的历史 Unⅸ虽然已经使用了40年,但计算机科学家仍然认为它是现存操作系统中最强大和最优秀的系统. Unix强大的根本原因: 简洁 在Unix中所有的东西都被 ...
- Beta 讨论分析——持续更新ing
wonderland Beta 讨论分析 标签(空格分隔): 软工实践 wonderland 主要工作: info信息: 1.关联账号界面:hbb 2.标签检索界面:hbb 3.近期活跃度(cf.hd ...
- 团队作业(五)-笔记app top5
在互联网快速发展的情况下,各个行业的软件层出不穷,五花八门.各个行业都有相当多的软件介入其中,在如此多的软件之中,便有了相当激烈的竞争角逐.今天我们十五万的总冠军就着笔记APP行业中位列top 5的软 ...
- Android Manifest文件
Manifest文件内容 1.自定义权限(Permission) : <permission android:description="string resource" a ...
- vue组件间的数据和方法传递
方法 1.父组件调用子组件:ref(在子组件中加上ref即可通过this.$refs.ref.method调用) 2.子组件调用父组件:emit(this.$emit(调用的方法名,传递的参数)) 数 ...
- 基于接口回调详解JUC中Callable和FutureTask实现原理
Callable接口和FutureTask实现类,是JUC(Java Util Concurrent)包中很重要的两个技术实现,它们使获取多线程运行结果成为可能.它们底层的实现,就是基于接口回调技术. ...