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现在要乘飞机旅行,他们选择了一家相 ...
随机推荐
- Gym 100818I Olympic Parade(位运算)
Olympic Parade http://acm.hust.edu.cn/vjudge/contest/view.action?cid=101594#problem/I [题意]: 给出N个数,找出 ...
- 关于C# XML序列化的一个BUG的修改
关于C# XML序列化的一个BUG的修改 在我前一篇博客中提到用XML序列化作为数据库的一个方案,@拿笔小心 提到他们在用XML序列化时,遇到了一个比较严重的bug,即XML不闭合,系统不能正确的加载 ...
- Win7关机出现关闭程序提示框
运行输入Gpedit.msc回车打开组策略,在左侧选计算机配置/管理模板/系统/关机选项,在右侧双击“关闭会阻止或取消关机的应用程序的自动终止功能”,在打开的提示框中选“已启用”,按确定即可.
- Android系统中Parcelable和Serializable的区别
转载:https://greenrobot.me/devpost/android-parcelable-serializable/ 进行Android开发的时候,我们都知道不能将对象的引用传给Acti ...
- Netty笔记
1 基本介绍 Bootstrap Netty应用程序通过设置 bootstrap(引导)类开始,该类提供了一个用于应用程序网络层配置的容器.Bootstrap有两种类型,一种是用于客户端的Bootst ...
- Jstl标签的使用
一. 配置 JSTL 包括两个 JAR 文件, jstl.jar 和 standard.jar .是什么没有必要管,重在应用( 1+1 ? =2 ,我们没有必要深究,只需要知道这么用就行.). 原文引 ...
- How to do Mathematics
著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注明出处.作者:匿名用户链接:http://www.zhihu.com/question/30087053/answer/47815698来源 ...
- C++转义字符使用
编码过程中字符串可能过长,这通常须要换行,对于换行转义字符\ ,使用时要保证\后无空格,否则会出现"error C2017:非法的转义字符 "错误 如 // ''\"后 ...
- CSS 布局总结——变宽度布局
变宽度布局 1-2-1 等比例变宽 总宽度设置 width: 85%; min-width: 650px; (关于IE6的min-width支持,可用) content 设置 width: 66%; ...
- Js Pattern - Namespace Pattern
bad code // BEFORE: 5 globals // Warning: antipattern // constructors function Parent() {} function ...