http://www.lydsy.com/JudgeOnline/problem.php?id=2763

这也算分层图最短路?

dp[i][j]到城市i,还剩k次免费次数的最短路

#include<queue>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm> using namespace std; #define N 10001
#define M 50001 int n,k;
int S,T; int tot;
int front[N],nxt[M<<],to[M<<],val[M<<]; int dp[N][];
bool vis[N][]; struct node
{
int pos,rest;
int dis; node(int Pos=,int Rest=,int Dis=):pos(Pos),rest(Rest),dis(Dis){} bool operator < (node p) const
{
return dis>p.dis;
}
}now;
priority_queue<node>q; void read(int &x)
{
x=; char c=getchar();
while(!isdigit(c)) c=getchar();
while(isdigit(c)) { x=x*+c-''; c=getchar(); }
} void add(int u,int v,int w)
{
to[++tot]=v; nxt[tot]=front[u]; front[u]=tot; val[tot]=w;
to[++tot]=u; nxt[tot]=front[v]; front[v]=tot; val[tot]=w;
} void dijkstra()
{
memset(dp,,sizeof(dp));
dp[S][k]=;
now.pos=S;
now.rest=k;
q.push(now);
int u,v,cnt;
while(!q.empty())
{
now=q.top();
q.pop();
u=now.pos;
cnt=now.rest;
if(vis[u][cnt]) continue;
vis[u][cnt]=true;
for(int i=front[u];i;i=nxt[i])
{
v=to[i];
if(dp[u][cnt]+val[i]<dp[v][cnt])
{
dp[v][cnt]=dp[u][cnt]+val[i];
q.push(node(v,cnt,dp[v][cnt]));
}
if(cnt && dp[u][cnt]<dp[v][cnt-])
{
dp[v][cnt-]=dp[u][cnt];
q.push(node(v,cnt-,dp[v][cnt-]));
}
}
}
} int main()
{
int m;
read(n); read(m); read(k);
read(S); read(T);
int u,v,w;
while(m--)
{
read(u); read(v); read(w);
add(u,v,w);
}
dijkstra();
int ans=1e9;
for(int i=;i<=k;++i) ans=min(ans,dp[T][i]);
printf("%d",ans);
}

2763: [JLOI2011]飞行路线

Time Limit: 10 Sec  Memory Limit: 128 MB
Submit: 3831  Solved: 1460
[Submit][Status][Discuss]

Description

Alice和Bob现在要乘飞机旅行,他们选择了一家相对便宜的航空公司。该航空公司一共在n个城市设有业务,设这些城市分别标记为0到n-1,一共有m种航线,每种航线连接两个城市,并且航线有一定的价格。Alice和Bob现在要从一个城市沿着航线到达另一个城市,途中可以进行转机。航空公司对他们这次旅行也推出优惠,他们可以免费在最多k种航线上搭乘飞机。那么Alice和Bob这次出行最少花费多少?

Input

数据的第一行有三个整数,n,m,k,分别表示城市数,航线数和免费乘坐次数。
第二行有两个整数,s,t,分别表示他们出行的起点城市编号和终点城市编号。(0<=s,t<n)
接下来有m行,每行三个整数,a,b,c,表示存在一种航线,能从城市a到达城市b,或从城市b到达城市a,价格为c。(0<=a,b<n,a与b不相等,0<=c<=1000)
 

Output

 
只有一行,包含一个整数,为最少花费。

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

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.

bzoj千题计划226:bzoj2763: [JLOI2011]飞行路线的更多相关文章

  1. bzoj千题计划300:bzoj4823: [Cqoi2017]老C的方块

    http://www.lydsy.com/JudgeOnline/problem.php?id=4823 讨厌的形状就是四联通图 且左右各连一个方块 那么破坏所有满足条件的四联通就好了 按上图方式染色 ...

  2. bzoj千题计划196:bzoj4826: [Hnoi2017]影魔

    http://www.lydsy.com/JudgeOnline/problem.php?id=4826 吐槽一下bzoj这道题的排版是真丑... 我还是粘洛谷的题面吧... 提供p1的攻击力:i,j ...

  3. bzoj千题计划280:bzoj4592: [Shoi2015]脑洞治疗仪

    http://www.lydsy.com/JudgeOnline/problem.php?id=4592 注意操作1 先挖再补,就是补的范围可以包含挖的范围 SHOI2015 的题 略水啊(逃) #i ...

  4. bzoj千题计划177:bzoj1858: [Scoi2010]序列操作

    http://www.lydsy.com/JudgeOnline/problem.php?id=1858 2018 自己写的第1题,一遍过 ^_^ 元旦快乐 #include<cstdio> ...

  5. bzoj千题计划317:bzoj4650: [Noi2016]优秀的拆分(后缀数组+差分)

    https://www.lydsy.com/JudgeOnline/problem.php?id=4650 如果能够预处理出 suf[i] 以i结尾的形式为AA的子串个数 pre[i] 以i开头的形式 ...

  6. bzoj千题计划304:bzoj3676: [Apio2014]回文串(回文自动机)

    https://www.lydsy.com/JudgeOnline/problem.php?id=3676 回文自动机模板题 4年前的APIO如今竟沦为模板,,,╮(╯▽╰)╭,唉 #include& ...

  7. bzoj千题计划292:bzoj2244: [SDOI2011]拦截导弹

    http://www.lydsy.com/JudgeOnline/problem.php?id=2244 每枚导弹成功拦截的概率 = 包含它的最长上升子序列个数/最长上升子序列总个数 pre_len ...

  8. bzoj千题计划278:bzoj4590: [Shoi2015]自动刷题机

    http://www.lydsy.com/JudgeOnline/problem.php?id=4590 二分 这么道水题 没long long WA了两发,没判-1WA了一发,二分写错WA了一发 最 ...

  9. bzoj千题计划250:bzoj3670: [Noi2014]动物园

    http://www.lydsy.com/JudgeOnline/problem.php?id=3670 法一:KMP+st表 抽离nxt数组,构成一棵树 若nxt[i]=j,则i作为j的子节点 那么 ...

随机推荐

  1. 将WebService部署到 SharePoint 2010 gac 缓存中,并用Log4Net记录日志到数据库

    最近做了一个sharePoint项目,需要实现的功能是,第三方网站访问我们sharePoint中的数据,通过Webservice方式实现文件的上传和下载. 于是代码工作完成了之后,本地调试没什么问题, ...

  2. nodejs安装及npm模块插件安装路径配置

    在学习完js后,我们就要进入nodejs的学习,因此就必须配置nodejs和npm的属性了. 我相信,个别人在安装时会遇到这样那样的问题,看着同学都已装好,难免会焦虑起来.于是就开始上网查找解决方案, ...

  3. unity学习路线_重新出发

    入门级 1.先观看视频教程做一个小案例 官方英文:Unity - Learn – Modules 国内中文:Sike学院 基础级 1.你需要接触完整性的教程网站 Siki学院 Unity游戏开发从入门 ...

  4. Daily Scrumming* 2015.12.13(Day 5)

    一.团队scrum meeting照片 二.今日总结 姓名 WorkItem ID 工作内容 签入链接以及备注说明  江昊 任务1063 查找与学习前端工具库,并写出一篇指导文档 https://gi ...

  5. akm

    队名--牛肉面不要牛肉不要面 队伍成员 211406285 林志松 [队长兼前端开发] 211606368 林书浩 [系统设计] 211606357 陈远军 [UI美工] 211606335 吴沂章 ...

  6. (小组)Git 常用命令整理

    Git 常用命令整理 取得Git仓库 初始化一个版本仓库 git init Clone远程版本库 git clone git@xbc.me:wordpress.git 添加远程版本库origin,语法 ...

  7. SDN 交换机迁移1

    A game-theoretic approach to elastic control in software-defined networking 2014 之前的交换机迁移的工作(ElastiC ...

  8. 第二个Sprint冲刺总结

    第二个Sprint冲刺总结 ( 1)团队Github: https://github.com/ouqifeng/EasyGoOperation.git ( 2 ) 团队贡献分: 廖焯燊:22 何武鹏: ...

  9. Alpha 冲刺十

    团队成员 051601135 岳冠宇 051604103 陈思孝 031602629 刘意晗 031602248 郑智文 031602234 王淇 会议照片 项目燃尽图 项目进展 完善各自部分 项目描 ...

  10. Jmeter使用笔记之意料之外的

    以下是在测试过程中按照以前loadrunner的思维来做的一点区别: 一.组织方式之setup 在用loadrunner做接口测试的时候如果不是针对login的测试,那么一般也会把login接口放到i ...