题面

题面

题解

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

#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. 每周开源项目分享-年轻人的第一个OAuth2.0 Server:hydra

    年轻人的第一个OAuth2.0 Server:hydra hydra 是什么呢? OpenID Connect certified OAuth2 Server - cloud native, secu ...

  2. equals和==方法比较(一)

    问题描述 今天在使用spotbugs代码走查时发现这样一个问题,两个Long类型的变量使用==判断数值是否相等,spotbugs提示这是一个很致命的错误,代码大概如下, Long l1=123l; L ...

  3. CentOS 6.5关闭防火墙

    关闭命令:  service iptables stop 永久关闭防火墙:chkconfig iptables off 两个命令同时运行,运行完成后查看防火墙关闭状态 service iptables ...

  4. Spring学习(六)-----Spring使用@Autowired注解自动装配

    Spring使用@Autowired注解自动装配 在上一篇 Spring学习(三)-----Spring自动装配Beans示例中,它会匹配当前Spring容器任何bean的属性自动装配.在大多数情况下 ...

  5. Jenkins单元测试

    Jenkins提供了一个开箱即用功能来选择JUnit,并提供了一系列的插件进行单元测试等技术,一个例子是 MSTest 的.Net单元测试.如果你打下面的链接 https://wiki.jenkins ...

  6. oracle的分号和斜杠/

    ;是执行语句必须的/是执行语句块必须的 比如执行一个触发器 CREATE OR REPLACE TRIGGER "TRG_1" BEFORE INSERT ON "CAT ...

  7. python序列和其它类型的比较

    序列对象可以与相同类型的其他对象比较.它们使用 字典顺序 进行比较:首先比较两个python序列的第一个元素,如果不同,那么这就决定了比较操作的结果.如果它们相同,就再比较每个序列的第二个元素,以此类 ...

  8. nginx 日志模块

    ngx_http_log_module.c 数据结构 typedef struct { void **main_conf; void **srv_conf; void **loc_conf;} ngx ...

  9. Professional Books

    Machine Learning:     Pattern Recognition and Machine Learning(PRML)    https://mqshen.gitbooks.io/p ...

  10. 5.airflow问题

    1. Traceback (most recent call last): File "/usr/bin/airflow", line 28, in <module> ...