题面

题面

题解

这题不是很难,因为删代价的次数不多,因此我们只需要将最短路中的状态加一维表示已经删了几次,再转移即可

#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]飞行路线 最短路的更多相关文章

  1. BZOJ 2763: [JLOI2011]飞行路线 最短路

    2763: [JLOI2011]飞行路线 Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://www.lydsy.com/JudgeOnline/pr ...

  2. bzoj2763: [JLOI2011]飞行路线 最短路

    题意:求最多可以有k条路免费的最短路 题解:用dis[x][k]表示从s开始用了k次免费机会到x的最短路,然后dij跑的时候优先队列里多维护一个k就好了 /********************** ...

  3. 分层图+最短路算法 BZOJ 2763: [JLOI2011]飞行路线

    2763: [JLOI2011]飞行路线 Time Limit: 10 Sec  Memory Limit: 128 MB Description Alice和Bob现在要乘飞机旅行,他们选择了一家相 ...

  4. Bzoj 2763: [JLOI2011]飞行路线 dijkstra,堆,最短路,分层图

    2763: [JLOI2011]飞行路线 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 1728  Solved: 649[Submit][Statu ...

  5. BZOJ2763 JLOI2011 飞行路线 【最短路+DP】

    BZOJ2763 JLOI2011 飞行路线 Description Alice和Bob现在要乘飞机旅行,他们选择了一家相对便宜的航空公司.该航空公司一共在n个城市设有业务,设这些城市分别标记为0到n ...

  6. 【bzoj2763】[JLOI2011]飞行路线 (分层图最短路)(优先队列dij)

    [bzoj2763][JLOI2011]飞行路线 2014年3月25日1,7260 Description Alice和Bob现在要乘飞机旅行,他们选择了一家相对便宜的航空公司.该航空公司一共在n个城 ...

  7. 分层图最短路【bzoj2763】: [JLOI2011]飞行路线

    bzoj2763: [JLOI2011]飞行路线 Description Alice和Bob现在要乘飞机旅行,他们选择了一家相对便宜的航空公司.该航空公司一共在n个城市设有业务,设这些城市分别标记为0 ...

  8. BZOJ2763[JLOI2011]飞行路线 [分层图最短路]

    2763: [JLOI2011]飞行路线 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 2523  Solved: 946[Submit][Statu ...

  9. poj 2763: [JLOI2011]飞行路线(spfa分层图最短路)

    2763: [JLOI2011]飞行路线 Time Limit: 10 Sec Memory Limit: 128 MB Submit: 2156 Solved: 818 [Submit][Statu ...

随机推荐

  1. rpmforge

    Could not retrieve mirrorlist http://mirrorlist.repoforge.org/el6/mirrors-rpmforge error was : PYCUR ...

  2. ubuntu 16.04 安装php 5 6等版本

    //加入ppa $ sudo add-apt-repository ppa:ondrej/php $ sudo apt-get update //安装5.6 $ sudo apt- //安装7 $ s ...

  3. Arduino语言

    Arduino语言 Arduino语言是建立在C/C++基础上的,其实也就是基础的C语言,Arduino语言只不过把AVR单片机(微控制器)相关的一些参数设置都函数化,不用我们去了解他的底层,让我们不 ...

  4. 发送请求工具—Advanced REST Client的安装使用

    1. 0 下载得到Advanced-REST-client_v3.1.9.zip 链接:http://pan.baidu.com/s/1c0vUnJi 密码:z34d 1.1 解压Advanced-R ...

  5. [MYSQL]练习(一)

    本文转载自:http://www.cnblogs.com/DreamDrive/p/6193530.html 我只是想做一个自己的运维知识库,所以迫不得已做了搬运工 建表 DROP TABLE DEP ...

  6. Linux系统网络安装——基于pxe+dhcp+nfs+tftp+kickstart

    原文发表于:2010-09-05 转载至cu于:2012-07-21 一.原理简介 PXE(preboot execute environment)工作于Client/Server的网络模式,支持工作 ...

  7. 《机器学习实战》6.2小节,KKT条件代码理解

    <机器学习实战>6.2小节 #这句是检测 当前样本点i 是否满足KKT条件的 if (alphas[i, :] < C and E_i * labelMat[i, :] < - ...

  8. RESTful源码笔记之RESTful Framework的基本组件

    快速实例 Quickstart 序列化 创建一个序列化类 简单使用 开发我们的Web API的第一件事是为我们的Web API提供一种将代码片段实例序列化和反序列化为诸如json之类的表示形式的方式. ...

  9. 将Python文件打包为exe文件,并在控制台运行之简易教程

       第一步  在线安装 pyinstaller. 方法:打开win+ R,输入cmd,在命令行输入"pip install pyinstaller" 静等几分钟后即可安装成功. ...

  10. 一些有趣的erlang项目

    这里会收集一些erlang项目,有需可以转. erlang-bookmarks Scaling Erlang High Performance Erlang - Finding Bottlenecks ...