[JLOI2011]飞行路线
2016-09-09 13:55
246 查看
bzoj2763
↑↑↑
题目
思路:
更改一下d数组的定义,把它变为2维。
d[i][j]表示到达i号点用了j次免费机会的最短路。
至于怎么推下一次状态也很简单,就分2种情况,用免费机会和不要免费机会。
就是这样
↓↓↓
9867
↑↑↑
题目
思路:
更改一下d数组的定义,把它变为2维。
d[i][j]表示到达i号点用了j次免费机会的最短路。
至于怎么推下一次状态也很简单,就分2种情况,用免费机会和不要免费机会。
就是这样
↓↓↓
if(d[x][c]+a[k].c<d[y][c]) { d[y][c]=d[x][c]+a[k].c; if(v[y][c]==false) { v[y][c]=true; list[tail][0]=y;list[tail++][1]=c; if(tail==100001) tail=1; } } if(d[x][c]<d[y][c+1]&&c<kk) { d[y][c+1]=d[x][c]; if(!v[y][c+1]) { v[y][c+1]=true; list[tail][0]=y;list[tail++][1]=c+1; if(tail==100001) tail=1; } }
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
struct node
{
int x,y,c,next;
}a[210000];int len,last[110000];
void ins(int x,int y,int c)
{
len++;
a[len].x=x;a[len].y=y;a[len].c=c;
a[len].next=last[x];last[x]=len;
}
int d[110000][11];
int list[110000][11],head,tail;
bool v[110000][11];
int main()
{
int n,m,kk,st,ed;
scanf("%d%d%d",&n,&m,&kk);
scanf("%d%d",&st,&ed);
for(int i=1;i<=m;i++)
{
int x,y,c;
scanf("%d%d%d",&x,&y,&c);
ins(x,y,c);
ins(y,x,c);
}
memset(d,31,sizeof(d));d[st][0]=0;
memset(v,false,sizeof(v));
v[st][0]=true;list[1][0]=st;list[1][1]=0;
head=1;tail=2;
while(head!=tail)
{
int x=list[head][0];int c=list[head][1];
for(int k=last[x];k;k=a[k].next)
{
int y=a[k].y;
if(d[x][c]+a[k].c<d[y][c]) { d[y][c]=d[x][c]+a[k].c; if(v[y][c]==false) { v[y][c]=true; list[tail][0]=y;list[tail++][1]=c; if(tail==100001) tail=1; } } if(d[x][c]<d[y][c+1]&&c<kk) { d[y][c+1]=d[x][c]; if(!v[y][c+1]) { v[y][c+1]=true; list[tail][0]=y;list[tail++][1]=c+1; if(tail==100001) tail=1; } }
}
head++;
if(head==100001) head=1;
v[x][c]=false;
}
int ans=999999999;
for(int i=0;i<=kk;i++){ans=min(ans,d[ed][i]);}
printf("%d\n",ans);
return 0;
}
9867
相关文章推荐
- bzoj2763 [JLOI2011]飞行路线
- 【bzoj2763】[JLOI2011]飞行路线 分层图最短路
- P4568 [JLOI2011]飞行路线
- BZOJ2763: [JLOI2011]飞行路线
- Bzoj 2763: [JLOI2011]飞行路线 拆点,分层图,最短路,SPFA
- 2763: [JLOI2011]飞行路线
- [BZOJ2763][JLOI2011][分层图最短路]飞行路线
- [JLOI2011]飞行路线
- [BZOJ2763][JLOI2011]飞行路线
- 【bzoj 2763】2763: [JLOI2011]飞行路线 spfa二维
- 【bzoj2763】 JLOI2011飞行路线 分层最短路
- 分层图最短路【bzoj2763】: [JLOI2011]飞行路线
- bzoj2763 [JLOI2011]飞行路线 Dijkstra
- BZOJ 2763 JLOI 2011 飞行路线 分层图+最短路
- 【BZOJ2763】【JLOI2011】飞行路线 分层图
- 分层图,bzoj2763: [JLOI2011]飞行路线
- bzoj 2763 [JLOI2011]飞行路线
- 【bzoj2763】【JLOI2011】【飞行路线】【dp+spfa】
- [JLOI2011]飞行路线 分层图最短路
- bzoj2763: [JLOI2011]飞行路线(分层图spfa)