[JLOI2011]飞行路线 最短路
题面
题解
这题不是很难,因为删代价的次数不多,因此我们只需要将最短路中的状态加一维表示已经删了几次,再转移即可
#include<bits/stdc++.h>
using namespace std;
#define R register int
#define AC 11000
#define ac 130000
int n, m, k, s, t, ans = 1000000000;
int Head[AC], date[ac], Next[ac], len[ac], tot;
int dis[AC][15];
bool vis[AC][15];
struct node{int x, dis, cost;};//编号 + 已经经过的距离 + 已经消耗的次数
struct cmp{bool operator () (node a, node b){return a.dis > b.dis;}};
priority_queue <node, vector<node>, cmp> q;
inline int read()
{
int x = 0;char c = getchar();
while(c > '9' || c < '0') c = getchar();
while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
return x;
}
inline void upmin(int &a, int b) {if(b < a) a = b;}
inline void add(int f, int w, int S)
{
date[++ tot] = w, Next[tot] = Head[f], Head[f] = tot, len[tot] = S;
date[++ tot] = f, Next[tot] = Head[w], Head[w] = tot, len[tot] = S;
}
void pre()
{
n = read(), m = read(), k = read();
s = read() + 1, t = read() + 1;
for(R i = 1; i <= m; i ++)
{
int x = read() + 1, y = read() + 1, S = read();
add(x, y, S);
}
}
void dij()
{
memset(dis, 127, sizeof(dis)), dis[s][0] = 0;
q.push((node){s, 0, 0});
while(!q.empty())
{
node x = q.top();
q.pop();
while(!q.empty() && vis[x.x][x.cost]) x = q.top(), q.pop();
if(vis[x.x][x.cost]) break;
vis[x.x][x.cost] = true;
for(R i = Head[x.x]; i; i = Next[i])
{
int now = date[i];
if(dis[now][x.cost] > dis[x.x][x.cost] + len[i])//不使用机会
{
dis[now][x.cost] = dis[x.x][x.cost] + len[i];
q.push((node){now, dis[now][x.cost], x.cost});
}
if(x.cost < k && dis[now][x.cost + 1] > dis[x.x][x.cost])
{
dis[now][x.cost + 1] = dis[x.x][x.cost];
q.push((node){now, dis[now][x.cost + 1], x.cost + 1});
}
}
}
for(R i = 0; i <= k; i ++) upmin(ans, dis[t][i]);
printf("%d\n", ans);
}
int main()
{
// freopen("in.in", "r", stdin);
pre();
dij();
// fclose(stdin);
return 0;
}
[JLOI2011]飞行路线 最短路的更多相关文章
- BZOJ 2763: [JLOI2011]飞行路线 最短路
2763: [JLOI2011]飞行路线 Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://www.lydsy.com/JudgeOnline/pr ...
- bzoj2763: [JLOI2011]飞行路线 最短路
题意:求最多可以有k条路免费的最短路 题解:用dis[x][k]表示从s开始用了k次免费机会到x的最短路,然后dij跑的时候优先队列里多维护一个k就好了 /********************** ...
- 分层图+最短路算法 BZOJ 2763: [JLOI2011]飞行路线
2763: [JLOI2011]飞行路线 Time Limit: 10 Sec Memory Limit: 128 MB Description Alice和Bob现在要乘飞机旅行,他们选择了一家相 ...
- Bzoj 2763: [JLOI2011]飞行路线 dijkstra,堆,最短路,分层图
2763: [JLOI2011]飞行路线 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 1728 Solved: 649[Submit][Statu ...
- BZOJ2763 JLOI2011 飞行路线 【最短路+DP】
BZOJ2763 JLOI2011 飞行路线 Description Alice和Bob现在要乘飞机旅行,他们选择了一家相对便宜的航空公司.该航空公司一共在n个城市设有业务,设这些城市分别标记为0到n ...
- 【bzoj2763】[JLOI2011]飞行路线 (分层图最短路)(优先队列dij)
[bzoj2763][JLOI2011]飞行路线 2014年3月25日1,7260 Description Alice和Bob现在要乘飞机旅行,他们选择了一家相对便宜的航空公司.该航空公司一共在n个城 ...
- 分层图最短路【bzoj2763】: [JLOI2011]飞行路线
bzoj2763: [JLOI2011]飞行路线 Description Alice和Bob现在要乘飞机旅行,他们选择了一家相对便宜的航空公司.该航空公司一共在n个城市设有业务,设这些城市分别标记为0 ...
- BZOJ2763[JLOI2011]飞行路线 [分层图最短路]
2763: [JLOI2011]飞行路线 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 2523 Solved: 946[Submit][Statu ...
- poj 2763: [JLOI2011]飞行路线(spfa分层图最短路)
2763: [JLOI2011]飞行路线 Time Limit: 10 Sec Memory Limit: 128 MB Submit: 2156 Solved: 818 [Submit][Statu ...
随机推荐
- vcruntime140.dll 丢失64位系统
1. 下载VC Redistributable for VS2015,网址https://www.microsoft.com/en-us/download/confirmation.aspx?id=4 ...
- Oracle dba权限下修改用户密码 授予用户权限 解锁用户
1.修改用户密码 alter user scott identified by 123 2.授予用户权限 grant connect,resource to scott 3.解锁用户 alter us ...
- Python中的矩阵操作
Numpy 通过观察Python的自有数据类型,我们可以发现Python原生并不提供多维数组的操作,那么为了处理矩阵,就需要使用第三方提供的相关的包. NumPy 是一个非常优秀的提供矩阵操作的包.N ...
- [转载] Centos7的安装、Docker1.12.3的安装,以及Docker Swarm集群的简单实例
1.环境准备 本文中的案例会有四台机器,他们的Host和IP地址如下 c1 -> 10.0.0.31 c2 -> 10.0.0.32 c3 -> 10.0.0.33 c4 -&g ...
- Hands on Machine Learning with sklearn and TensorFlow —— 一个完整的机器学习项目(加州房地产)
数据集地址:https://github.com/ageron/handson-ml/tree/master/datasets 先行知识准备:NumPy,Pandas,Matplotlib的模块使用 ...
- 数据库mysql的常规操作
1. 什么是数据库? 数据库(Database)是按照数据结构来组织.存储和管理数据的建立在计算机存储设备上的仓库. 简单来说是本身可视为电子化的文件柜——存储电子文件的处所,用户可以对文件中的数据进 ...
- 《机器学习实战》6.2小节,KKT条件代码理解
<机器学习实战>6.2小节 #这句是检测 当前样本点i 是否满足KKT条件的 if (alphas[i, :] < C and E_i * labelMat[i, :] < - ...
- JPA error org.hibernate.AnnotationException: No identifier specified for entity
错误:org.hibernate.AnnotationException: No identifier specified for entity 原因:JPA所使用的Entity需要标注@Id,在引用 ...
- [笔记] postgresql 流复制(streaming replication)
基本环境说明: os:FreeBSD 9.3 postgresql version: master:192.168.56.101 standby:192.168.56.102 安装过程略,基于pkg包 ...
- Android:有关菜单的学习(供自己参考)
Android:有关==菜单==的学习 上下文菜单 上下文菜单就是手机中对某一项进行==点击一定时间==后弹出的针对该项处理的菜单. context_menu.xml: <?xml versio ...