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的子节点 那么 ...
随机推荐
- 如何解决markdown中图片上传的问题
1.第一种方式(图床) 1.1 google中的插件-新浪微博图床 2.第二种方式,操作流程如下 2.1 下载一个有道云笔记客户端 2.2 然后把图片通过有道云笔记分享出来,见下动态图 3.总结一下 ...
- Linux Mint安装Docker踩坑指南
我家的服务器选用的Linux Mint系统,最近安装Docker的时候踩了一些小坑,但是总体还算顺利. 我们都知道Linux Mint系统是基于Ubuntu的,说实话用起来感觉还是很不错的,安装Doc ...
- 06-docker组件如何协作
容器启动过程如下: Docker 客户端执行 docker run 命令. Docker daemon 发现本地没有 httpd 镜像. daemon 从 Docker Hub 下载镜像. 下载完成, ...
- mysql学习(2)-Navicat Premium 12 链接MySQL8.0.11数据库报2059错误
Navicat Premium 12 链接MySQL8.0.11数据库报2059错误 1,问题现象 安装完MySQL8.0.11和Navicat Premium12后,我们会用Navicat去测试连接 ...
- 数据库——SQL数据单表查询
数据查询 语句格式 SELECT [ALL|DISTINCT] <目标列表达式> [,<目标列表达式>] … FROM <表或视图名>[,<表或视图名&g ...
- [2017BUAA软工助教]结对组队
请同学们把第一次结对编程双方的学号评论在本博客下,只要一位同学评论即可.例如: 14061195 + 14061183
- 《Linux内核分析》第三周学习报告
<Linux内核分析>第三周学习报告 ——构造一个简单的Linux系统MenuOS 姓名:王玮怡 学号:201351 ...
- Sprint计划会议内容
项目名称:蹭课神器 会议内容 首先我们讨论了项目的工作量及实施流程 一.工作认领 二.界面的总体规划 三.主要功能的设计 四.设计数据库 五.编写项目报告 六.软件测试和推广 然后我们进行了工作认领, ...
- [Docker基础]如何清除不用的资源
Docker - How to cleanup resources 有时你可能需要清理Docker中不用的资源,特别是在学习Docker过程中创建的镜像.容器.网络.存储卷等. delete volu ...
- 《TCP-IP详解卷1》中BGP部分的笔记