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现在要乘飞机旅行,他们选择了一家相 ...
随机推荐
- 【转】有向图强连通分量的Tarjan算法
原文地址:https://www.byvoid.com/blog/scc-tarjan/ [有向图强连通分量] 在有向图G中,如果两个顶点间至少存在一条路径,称两个顶点强连通(strongly con ...
- hdu 2824 The Euler function
The Euler function Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Other ...
- codeforces 625C K-special Tables
C. K-special Tables time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- 在 Web 层应用程序中使用Spring
前面已经配置成功后,就可以在Web 层的Servlet或Jsp中调用访问Spring了,如果你 编制的是一个Servlet/Jsp 程序,那么在你的Servlet/Jsp 使用下面的代码通过Sprin ...
- HDU 1078 FatMouse and Cheese (记忆化搜索)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1078 老鼠初始时在n*n的矩阵的(0 , 0)位置,每次可以向垂直或水平的一个方向移动1到k格,每次移 ...
- contest7.20(暴力专练)
此次练习的地址: http://acm.hust.edu.cn/vjudge/contest/view.action?cid=26732#overview 密码 acmore Problem A(P ...
- Mac下的eclipse 4.6的tomcat插件安装正确姿势
最新版 eclipse 4.6 (Neon) tomcat 插件的安装, 解决tomcat插件tomcatPluginV331不能使用的问题. 1.打开最新版的 eclipse 4.6 (neon), ...
- Unity3D之移植学习笔记:移植到Android平台
首先,我们需要一台已经配置好可以开发Android应用的计算机,这里我使用的是Windows系统+Eclipse+ADT的开发环境,当然也可以使用Android Studio或者使用Mac系统都可以. ...
- 字串数_hdu_1261(大数极致).java
字串数 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submis ...
- 如何将std::string转int,double? (C/C++) (C) (template)
http://www.cnblogs.com/oomusou/archive/2008/08/01/525647.html http://blog.sina.com.cn/s/blog_a843a88 ...