[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 ...
随机推荐
- 【mysql优化】mysql count(*)、count(1)、count(主键字段)、count(非主键字段)哪个性能最佳
测试结果为:count(*)和count(1)基本相等,count(非主键字段)最耗性能 -- 数据量 708254select count(*) from tmp_test1;-- avg 0.22 ...
- C# 调用C++ dll 返回char*调用方式(StringBuilder乱码)
// CDLLDemo.cpp : 定义 DLL 应用程序的导出函数. // #include "stdafx.h" #include "string.h" # ...
- WPF DrawingContext Pen
<Window x:Class="WPFDrawing.MainWindow" xmlns="http://schemas.microsoft.com/winfx/ ...
- 我们一起学习WCF 第五篇数据协定和消息协定
A:数据协定(“数据协定”是在服务与客户端之间达成的正式协议,用于以抽象方式描述要交换的数据. 也就是说,为了进行通信,客户端和服务不必共享相同的类型,而只需共享相同的数据协定. 数据协定为每个参数或 ...
- fastCMS数据库相关操作类
fastCMS针对数据库的操作有以下几个类: 1.[paging_Class]分页类 此类用于分页检索数据库内符合条件的记录 1) 支持百万级数据分页 2) 支持多种类型的SQL语法,比如 Left ...
- CSP201312-3:最大的矩形
引言:CSP(http://www.cspro.org/lead/application/ccf/login.jsp)是由中国计算机学会(CCF)发起的"计算机职业资格认证"考试, ...
- 使用HackRF和外部时钟实现GPS欺骗实验
本文内容.开发板及配件仅限用于学校或科研院所开展科研实验! 淘宝店铺名称:开源SDR实验室 HackRF链接:https://item.taobao.com/item.htm?spm=a1z10.1- ...
- H2O Driverless AI
H2O Driverless AI(H2O无驱动人工智能平台)是一个自动化的机器学习平台,它给你一个有着丰富经验的“数据科学家之盒”来完成你的算法. 使AI技术得到大规模应用 各地的企业都意识到人工智 ...
- 最强NLP模型-BERT
简介: BERT,全称Bidirectional Encoder Representations from Transformers,是一个预训练的语言模型,可以通过它得到文本表示,然后用于下游任务, ...
- Halcon如何保存仿射变换矩阵
这里我们通过序列化来实现的,如下图,写到硬盘的HomMat2D_1内容和从硬盘里HomMat2D_2读出的内容一致,源代码在图片下方. Halcon源代码: hom_mat2d_identity (H ...