BZOJ 2763 [JLOI2011]飞行路线
来源:互联网 发布:linux c代码创建目录 编辑:程序博客网 时间:2024/05/29 13:02
分层图
记f[i][j]表示在i,且还可以免费j次的最小代价,直接跑类似最短路即可
#include<cstdio>#include<queue>#include<cstring>#include<algorithm>#define N 10005#define M 50001using namespace std;struct edge{int next,to,v;}e[M<<1];const int INF = 0x7fffffff;int ecnt=1, last[N], f[N][12], n, m, k, s, t;bool vis[N][12];void add(int a, int b, int c){ e[++ecnt]=(edge){last[a],b,c}; last[a]=ecnt;}struct node{int id, step;};void SPFA(){ queue<node> q; memset(f,63,sizeof(f)); f[s][k]=0; q.push((node){s,k}); while(!q.empty()) { int x=q.front().id, step=q.front().step; q.pop(); vis[x][step]=0; for(int i = last[x]; i; i=e[i].next) { int y=e[i].to; if(f[y][step]>f[x][step]+e[i].v) { f[y][step]=f[x][step]+e[i].v; if(!vis[y][step]) { vis[y][step]=1; q.push((node){y,step}); } } if(step >= 1 && f[y][step-1]>f[x][step]) { f[y][step-1]=f[x][step]; if(!vis[y][step-1]) { vis[y][step-1]=1; q.push((node){y,step-1}); } } } }}int main(){ scanf("%d%d%d%d%d",&n,&m,&k,&s,&t); for(int i = 1, a, b, c; i <= m; i++) scanf("%d%d%d",&a,&b,&c),add(a,b,c),add(b,a,c); SPFA(); int ans=INF; for(int i = 0; i <= k; i++) ans=min(ans,f[t][i]); printf("%d\n",ans);}
0 0
- BZOJ 2763: [JLOI2011]飞行路线
- bzoj 2763 [JLOI2011]飞行路线
- BZOJ 2763 [JLOI2011]飞行路线
- BZOJ 2763 [JLOI2011]飞行路线
- bzoj 2763: [JLOI2011]飞行路线
- bzoj 2763: [JLOI2011]飞行路线
- BZOJ 2763 [JLOI2011]飞行路线
- bzoj[JLOI2011]飞行路线
- 【BZOJ】【JLOI2011】飞行路线
- BZOJ 2763 [JLOI2011]飞行路线 Dijikstra
- BZOJ 2763: [JLOI2011]飞行路线 最短路
- |BZOJ 2763|最短路|[JLOI2011]飞行路线
- bzoj 2763 [JLOI2011]飞行路线 Dijikstra 分层
- BZOJ[2763][JLOI2011]飞行路线 spfa
- 2763: [JLOI2011]飞行路线
- 2763: [JLOI2011]飞行路线
- 2763: [JLOI2011]飞行路线
- 2763: [JLOI2011]飞行路线
- AbstractFactory_Level4
- Java 面试锦集
- 《Asp.Net Web API》-----webApi的简单使用
- 在Linux-as5u2-64下安装JIRA6.4.3
- Leetcode---Longest Palindromic Substring
- BZOJ 2763 [JLOI2011]飞行路线
- String android.content.Context.getString(int resId, Object... formatArgs)
- iOS10适配开发
- Yeoman安装和使用详解
- 使用StarUML 画UML 类图 by Java
- 集合框架Collection之list接口
- SSL与TLS的区别以及介绍
- python 输出带颜色
- Vue中阻止时间冒泡方法