bzoj千题计划226:bzoj2763: [JLOI2011]飞行路线
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
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.
bzoj千题计划226:bzoj2763: [JLOI2011]飞行路线的更多相关文章
- bzoj千题计划300:bzoj4823: [Cqoi2017]老C的方块
http://www.lydsy.com/JudgeOnline/problem.php?id=4823 讨厌的形状就是四联通图 且左右各连一个方块 那么破坏所有满足条件的四联通就好了 按上图方式染色 ...
- bzoj千题计划196:bzoj4826: [Hnoi2017]影魔
http://www.lydsy.com/JudgeOnline/problem.php?id=4826 吐槽一下bzoj这道题的排版是真丑... 我还是粘洛谷的题面吧... 提供p1的攻击力:i,j ...
- bzoj千题计划280:bzoj4592: [Shoi2015]脑洞治疗仪
http://www.lydsy.com/JudgeOnline/problem.php?id=4592 注意操作1 先挖再补,就是补的范围可以包含挖的范围 SHOI2015 的题 略水啊(逃) #i ...
- bzoj千题计划177:bzoj1858: [Scoi2010]序列操作
http://www.lydsy.com/JudgeOnline/problem.php?id=1858 2018 自己写的第1题,一遍过 ^_^ 元旦快乐 #include<cstdio> ...
- bzoj千题计划317:bzoj4650: [Noi2016]优秀的拆分(后缀数组+差分)
https://www.lydsy.com/JudgeOnline/problem.php?id=4650 如果能够预处理出 suf[i] 以i结尾的形式为AA的子串个数 pre[i] 以i开头的形式 ...
- bzoj千题计划304:bzoj3676: [Apio2014]回文串(回文自动机)
https://www.lydsy.com/JudgeOnline/problem.php?id=3676 回文自动机模板题 4年前的APIO如今竟沦为模板,,,╮(╯▽╰)╭,唉 #include& ...
- bzoj千题计划292:bzoj2244: [SDOI2011]拦截导弹
http://www.lydsy.com/JudgeOnline/problem.php?id=2244 每枚导弹成功拦截的概率 = 包含它的最长上升子序列个数/最长上升子序列总个数 pre_len ...
- bzoj千题计划278:bzoj4590: [Shoi2015]自动刷题机
http://www.lydsy.com/JudgeOnline/problem.php?id=4590 二分 这么道水题 没long long WA了两发,没判-1WA了一发,二分写错WA了一发 最 ...
- bzoj千题计划250:bzoj3670: [Noi2014]动物园
http://www.lydsy.com/JudgeOnline/problem.php?id=3670 法一:KMP+st表 抽离nxt数组,构成一棵树 若nxt[i]=j,则i作为j的子节点 那么 ...
随机推荐
- [2017BUAA软工助教]结对项目小结
2017BUAA结对项目小结 一.作业链接 http://www.cnblogs.com/jiel/p/7604111.html 二.评分细则 1.注意事项 按时间完成并提交--正常评分 晚交一周以内 ...
- Linux 第五章 学习笔记
---恢复内容开始--- 第五章 系统调用 一.与内核通信 1.系统调用在用户控件进程和硬件设备之间添加了一个中间层. 为用户空间提供了一种硬件的抽象接口 系统调用保证了系统的稳定和安全 每个进程都运 ...
- SDN可靠性相关
A subtree-based approach to failure detection and protection for multicast in SDN FRONTIERS OF INFOR ...
- Leetcode题库——49.字母异位词分组【##】
@author: ZZQ @software: PyCharm @file: leetcode49_groupAnagrams.py @time: 2018/11/19 13:18 要求:给定一个字符 ...
- Daily Scrum 10.22
(写于10.22周四0晨) 昨天任务还未完成的继续完成任务. 每个人都查看自己的TFS,修改已经完成的任务状态,改为已关闭-已完成. 由于android studio运行过于慢,我们统一采取eclip ...
- 在 Ubuntu16.04 中搭建 Spark 单机开发环境 (JDK + Scala + Spark)
1.准备 本文主要讲述如何在Ubuntu 16.04 中搭建 Spark 2.11 单机开发环境,主要分为 3 部分:JDK 安装,Scala 安装和 Spark 安装. JDK 1.8:jdk-8u ...
- 圆桌的项目Alpha冲刺——测试
测试工作安排 作为一个测试计划来讲,核心的三个要素是时间,资源,范围.时间就是什么时候做以及要花多久做,资源就是你要调用的人力.机器等资源,范围是你要测试的东西以及测试重点. 时间:每天完成相应的模块 ...
- node模块加载机制。
- Linux命令(十六) 压缩或解压缩文件和目录 zip unzip
目录 1.命令简介 2.常用参数介绍 3.实例 4.直达底部 命令简介 zip 是 Linux 系统下广泛使用的压缩程序,文件压缩后扩展名为 ".zip". zip 命令用来将文件 ...
- [转帖] 一文看懂:"边缘计算"究竟是什么?为何潜力无限?
一文看懂:"边缘计算"究竟是什么?为何潜力无限? 转载cnbeta 云计算 雾计算 边缘计算... 知名创投调研机构CB Insights撰文详述了边缘计算的发展和应用前景 ...