BZOJ 2763
2763: [JLOI2011]飞行路线
Time Limit: 10 Sec Memory Limit: 128 MB
Submit: 2073 Solved: 790
[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.
Source
题解:
分层图最短路
每个点的意义是走到第i个点,已经免费了k次的最少花费,建图就比较显然了。注意这道题建图只需要建一层,然后手写转移,这样比较快。
f[i][j]表示从起点开始,使用i次免费机会,到达j点的最小消费值。
ps:要加堆优化,否则会T。
#include<cstdio>
#include<cstring>
#include<queue>
#include<iostream>
using namespace std;
const int N=1e5+;
int n,m,k,from,to,tot,v[N],w[N],head[N],next[N],f[][N];
bool vis[][N];
struct node{
int step,p;
bool operator <(const node &a)const {return f[step][p]>f[a.step][a.p];}
};
inline void add(int x,int y,int z){
v[++tot]=y;w[tot]=z;next[tot]=head[x];head[x]=tot;
}
inline void spfa(){
static priority_queue<node>que;
memset(f,/,sizeof f);
que.push((node){,from});
f[][from]=;
while(!que.empty()){
node h=que.top();que.pop();
int x=h.p,step=h.step;
vis[step][x]=;
for(int i=head[x];i;i=next[i]){
if(f[step][v[i]]>f[step][x]+w[i]){
f[step][v[i]]=f[step][x]+w[i];
if(!vis[step][v[i]]){
vis[step][v[i]]=;
que.push((node){step,v[i]});
}
}
if(f[step+][v[i]]>f[step][x]&&step<k){
f[step+][v[i]]=f[step][x];
if(!vis[step+][v[i]]){
vis[step+][v[i]]=;
que.push((node){step+,v[i]});
} }
}
}
}
int main(){
scanf("%d%d%d",&n,&m,&k);
scanf("%d%d",&from,&to);from++;to++;
for(int i=,x,y,z;i<=m;i++) scanf("%d%d%d",&x,&y,&z),x++,y++,add(x,y,z),add(y,x,z);
spfa();
int ans=0x7fffffff;
for(int i=;i<=k;i++) ans=min(ans,f[i][to]);
printf("%d\n",ans);
return ;
}
BZOJ 2763的更多相关文章
- ACM-ICPC 2018 南京赛区网络预赛 L && BZOJ 2763 分层最短路
https://nanti.jisuanke.com/t/31001 题意 可以把k条边的权值变为0,求s到t的最短路 解析 分层最短路 我们建立k+1层图 层与层之间边权为0,i 向 i+1层转 ...
- 分层图+最短路算法 BZOJ 2763: [JLOI2011]飞行路线
2763: [JLOI2011]飞行路线 Time Limit: 10 Sec Memory Limit: 128 MB Description Alice和Bob现在要乘飞机旅行,他们选择了一家相 ...
- BZOJ 2763: [JLOI2011]飞行路线 spfa dp
题目链接: http://www.lydsy.com/JudgeOnline/problem.php?id=2763 题解: d[x][kk]表示从s到x用了kk次免费机会的最少花费. 代码: #in ...
- BZOJ 2763: [JLOI2011]飞行路线 最短路
2763: [JLOI2011]飞行路线 Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://www.lydsy.com/JudgeOnline/pr ...
- Bzoj 2763: [JLOI2011]飞行路线 dijkstra,堆,最短路,分层图
2763: [JLOI2011]飞行路线 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 1728 Solved: 649[Submit][Statu ...
- Bzoj 2763: [JLOI2011]飞行路线 拆点,分层图,最短路,SPFA
2763: [JLOI2011]飞行路线 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 1694 Solved: 635[Submit][Statu ...
- BZOJ 2763 飞行路线 BFS分层
题目链接: https://www.lydsy.com/JudgeOnline/problem.php?id=2763 题目大意: Alice和Bob现在要乘飞机旅行,他们选择了一家相对便宜的航空公司 ...
- [BZOJ 2763][JLOI 2011] 飞行路线
2763: [JLOI2011]飞行路线 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 3203 Solved: 1223[Submit][Stat ...
- bzoj 2763: [JLOI2011]飞行路线 -- 分层图最短路
2763: [JLOI2011]飞行路线 Time Limit: 10 Sec Memory Limit: 128 MB Description Alice和Bob现在要乘飞机旅行,他们选择了一家相 ...
随机推荐
- Linux递归删除文件命令
Linux递归删除文件命令 find . -name "*.log.*" -exec ls {} \; find . -name "*.log.*" -exec ...
- Serializable 序列化为文件
package test; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundExcept ...
- 201. Segment Tree Build
最后更新 二刷 08-Jan-2017 一刷忘了什么时候做的,只是觉得这几个题挺好的,一步一步手动构建线段树,最终理解了这个数据结构,并且后面有利用的地方. 其实重要的3个东西题目已经提供了: 1) ...
- presentedViewController 和 presentingViewController 以及 dismissViewControllerAnimated 的使用
在日常的开发中,多控制器之间的跳转除了使用push的方式,还可以使用 present的方式,present控制器时,就避免不了使用 presentedViewController.presenting ...
- shell脚本的入参
shell脚本参数可以任意多,但只有前9个可以被访问,使用shift命令可以改变这个限制.参数从第一个开始,在第九个结束.$0 程序名字$n 第n个参数值,n=1..9 $* 所有命令行参数$@ ...
- 在VS.NET中根据条件设置不同的MainForm
在VS.NET中有时候需要根据不同的条件设置不同的MainForm,例如:在程序第一次运行时候打开设置基本信息或服务器信息窗口等. 1.找到VS.NET中设置MainForm的窗口: 2.在编辑窗口中 ...
- VS~单步调试DLL
有时我们从第三方下载DLL库之后,在使用VS进行调试时还是很麻烦的,现在我总结一下,在开发过过程中调试DLL的方法,希望对各位在开发中有帮助. 1 VS下载插件.Net Refector 2 引用你的 ...
- VMWare里安装64位Linux 的方法
1.CPU AMD系列的CPU略过 Intel系列的CPU芯片需要支持EM64T和VT技术才行,并且BIOS也要支持才可以. 为了确定你的Intel CPU是否支持VT,请查看: http://com ...
- phpStudy 2014的Apache虚拟主机配置
安装phpStudy直接百度下载,傻瓜式安装很简单,一直点击下一步即可,中途根据个人爱好设置WWW目录,我的设置在D盘根目录里. 打开虚拟主机配置,打开D:\phpStudy\Apache\conf下 ...
- Codeforces Round #333 (Div. 1) C. Kleofáš and the n-thlon 树状数组优化dp
C. Kleofáš and the n-thlon Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contes ...