[JLOI2011]飞行路线
2016-09-12 14:04
211 查看
Description
最短路,给起点和终点,前k个点免费。
Sample Input
5 6 1 0 4 0 1 5 1 2 5 2 3 5 3 4 5 2 3 3 0 2 100
Sample Output
8
只要改一下d的定义,d[i][k],表示到第i个点,用k次免费。然后改操作,即可。
#include<cstdio> #include<cstring> using namespace std; struct node { int x,y,d,next; }a[210000];int len,last[110000]; void ins(int x,int y,int d) { len++; a[len].x=x;a[len].y=y;a[len].d=d; a[len].next=last[x];last[x]=len; } struct linode { int x,hh; }list[210000]; int d[11000][20]; bool v[11000][20]; int main() { int n,m,K,st,ed,x,y,c; scanf("%d%d%d",&n,&m,&K); scanf("%d%d",&st,&ed);st++;ed++; len=0;memset(last,0,sizeof(last)); for(int i=1;i<=m;i++) { scanf("%d%d%d",&x,&y,&c);x++;y++; ins(x,y,c);ins(y,x,c); } memset(v,false,sizeof(v));v[st][0]=true; for(int i=1;i<=n;i++)for(int j=0;j<=K;j++)d[i][j]=999999999; d[st][0]=0;list[1].x=st;list[1].hh=0; int head=1,tail=2,ans=999999999; while(head!=tail) { x=list[head].x;int hh=list[head].hh; if(x==ed){if(d[x][hh]<ans)ans=d[x][hh];} for(int k=last[x];k;k=a[k].next) { y=a[k].y; if(d[y][hh]>d[x][hh]+a[k].d) { d[y][hh]=d[x][hh]+a[k].d; if(v[y][hh]==false) { v[y][hh]=true; list[tail].x=y;list[tail].hh=hh; tail++;if(tail==200001)tail=1; } } if(hh+1<=K&&d[y][hh+1]>d[x][hh]) { d[y][hh+1]=d[x][hh]; if(v[y][hh+1]==false) { v[y][hh+1]=true; list[tail].x=y;list[tail].hh=hh+1; tail++;if(tail==200001)tail=1; } } } v[x][hh]=false; head++;if(head==200001)head=1; } printf("%d\n",ans); return 0; }
相关文章推荐
- bzoj2763 [JLOI2011]飞行路线
- BZOJ 2763: [JLOI2011]飞行路线 spfa dp
- [JLOI2011]飞行路线
- BZOJ 2763: [JLOI2011]飞行路线 【SPFA】
- BZOJ2763: [JLOI2011]飞行路线
- [BZOJ2763][JLOI2011]飞行路线(分层图最短路)
- |BZOJ 2763|最短路|[JLOI2011]飞行路线
- Bzoj 2763: [JLOI2011]飞行路线 dijkstra,堆,最短路,分层图
- [bzoj 2763--JLOI2011]飞行路线
- BZOJ 2763: [JLOI2011]飞行路线(最短路)
- bzoj千题计划226:bzoj2763: [JLOI2011]飞行路线
- bzoj 2763: [JLOI2011]飞行路线 -- 分层图最短路
- bzoj 2763 [JLOI2011]飞行路线 Dijikstra 分层
- BZOJ2763 [JLOI2011]飞行路线
- BZOJ2763[JLOI2011]飞行路线 [分层图最短路]
- [bzoj2763][JLOI2011]飞行路线——分层图最短路
- 【bzoj2763】[JLOI2011]飞行路线 (分层图最短路)(优先队列dij)
- [JLOI2011]飞行路线 不同的算法,不同的悲伤
- bzoj 2763 [JLOI2011]飞行路线 Dijikstra 分层
- BZOJ 2763: [JLOI2011]飞行路线