[bzoj2763][JLOI2011]飞行路线——分层图最短路
水题。不多说什么。
#include <bits/stdc++.h>
using namespace std;
const int maxn = 10010;
const int maxk = 15;
int n, m, k, s, t;
struct edge {
int to, value;
};
struct state {
int pos;
int k;
};
vector<edge> G[maxn];
int dist[maxn][maxk], inq[maxn][maxk];
void add_edge(int u, int v, int w) {
G[u].push_back((edge){v, w});
G[v].push_back((edge){u, w});
}
void spfa() {
memset(dist, 0x3f, sizeof(dist));
dist[s][0] = 0;
queue<state> q;
q.push((state){s, 0});
memset(inq, 0, sizeof(inq));
inq[s][0] = 1;
while (!q.empty()) {
state u = q.front();
q.pop();
inq[u.pos][u.k] = 0;
for (int i = 0; i < G[u.pos].size(); i++) {
edge &e = G[u.pos][i];
if (dist[e.to][u.k] > dist[u.pos][u.k] + e.value) {
dist[e.to][u.k] = dist[u.pos][u.k] + e.value;
if (!inq[e.to][u.k]) {
q.push((state){e.to, u.k});
inq[e.to][u.k] = 1;
}
}
if (u.k < k && dist[e.to][u.k + 1] > dist[u.pos][u.k]) {
dist[e.to][u.k + 1] = dist[u.pos][u.k];
if (!inq[e.to][u.k + 1]) {
q.push((state){e.to, u.k + 1});
inq[e.to][u.k + 1] = 1;
}
}
}
}
}
int main() {
// freopen("input", "r", stdin);
scanf("%d %d %d", &n, &m, &k);
scanf("%d %d", &s, &t);
while (m--) {
int a, b, c;
scanf("%d %d %d", &a, &b, &c);
add_edge(a, b, c);
}
spfa();
int ans = 0x3f3f3f;
for (int i = 0; i <= k; i++)
ans = min(ans, dist[t][i]);
printf("%d\n", ans);
return 0;
}
[bzoj2763][JLOI2011]飞行路线——分层图最短路的更多相关文章
- BZOJ2763: [JLOI2011]飞行路线(分层图 最短路)
题意 题目链接 Sol 分层图+最短路 建\(k+1\)层图,对于边\((u, v, w)\),首先在本层内连边权为\(w\)的无向边,再各向下一层对应的节点连边权为\(0\)的有向边 如果是取最大最 ...
- BZOJ2763[JLOI2011]飞行路线 [分层图最短路]
2763: [JLOI2011]飞行路线 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 2523 Solved: 946[Submit][Statu ...
- bzoj2763 [JLOI]飞行路线 分层图最短路
问题描述 Alice和Bob现在要乘飞机旅行,他们选择了一家相对便宜的航空公司.该航空公司一共在n个城市设有业务,设这些城市分别标记为0到n-1,一共有m种航线,每种航线连接两个城市,并且航线有一定的 ...
- bzoj2763: [JLOI2011]飞行路线(分层图spfa)
2763: [JLOI2011]飞行路线 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 3234 Solved: 1235[Submit][Stat ...
- [JLOI2011]飞行路线 分层图最短路
题目描述: Alice和Bob现在要乘飞机旅行,他们选择了一家相对便宜的航空公司.该航空公司一共在nn个城市设有业务,设这些城市分别标记为0到n-1,一共有m种航线,每种航线连接两个城市,并且航线有一 ...
- P4568 [JLOI2011]飞行路线 分层图最短路
思路:裸的分层图最短路 提交:1次 题解: 如思路 代码: #include<cstdio> #include<iostream> #include<cstring> ...
- 【bzoj2763】[JLOI2011]飞行路线 分层图最短路
题目描述 Alice和Bob现在要乘飞机旅行,他们选择了一家相对便宜的航空公司.该航空公司一共在n个城市设有业务,设这些城市分别标记为0到n-1,一共有m种航线,每种航线连接两个城市,并且航线有一定的 ...
- bzoj 2763: [JLOI2011]飞行路线 -- 分层图最短路
2763: [JLOI2011]飞行路线 Time Limit: 10 Sec Memory Limit: 128 MB Description Alice和Bob现在要乘飞机旅行,他们选择了一家相 ...
- bzoj2763 [JLOI2011]飞行路线——分层图
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=2763 构建分层图. 代码如下: 写法1(空间略大)(时间很慢): #include<i ...
随机推荐
- POJ 2761 Feed the dogs(平衡树or划分树or主席树)
Description Wind loves pretty dogs very much, and she has n pet dogs. So Jiajia has to feed the dogs ...
- URAL 1932 The Secret of Identifier(容斥)
Description Davy Jones: You've been captain of the Black Pearl for 13 years. That was our agreement. ...
- js把字符串格式的时间转换成几秒前、几分钟前、几小时前、几天前等格式
最近在做项目的时候,需要把后台返回的时间转换成几秒前.几分钟前.几小时前.几天前等的格式:后台返回的时间格式为:2015-07-30 09:36:10,需要根据当前的时间与返回的时间进行对比,最后显示 ...
- bootsrap 上传插件fileinput 简单使用
1.安装 下载fileinput文件,载入对应的css+js文件,如下: <link href="css/bootstrap.min.css" rel="style ...
- PHP与webserver【简书看到的】
很久以前,人们造出来一个机器人,它的英文名字叫web server,中文名叫网页服务器.(为了简写,下文称web server为server) server的工作很简单,就是做内容的分发. 初期的se ...
- 框架开发中的junit单元测试
首先写一个测试用的公共类,如果要搭建测试环境,只要继承这个公共类就能很容易的实现单元测试,代码如下 import org.junit.runner.RunWith; import org.spring ...
- 【题解】SDOI2010地精部落
强!强!强!强!劲啊劲啊劲啊!!!洛谷P2467 非常重要的,就在于发现以下的两条性质: 1.当i与i+1不相邻时,方案数是一样的:交换这两个数,<i+1的必然<i,>i+1的必然& ...
- [CF1019A]Elections
题目大意:有$n$个人,$m$个政党,每个人都想投一个政党,但可以用一定的钱让他选你想让他选的政党. 现在要$1$号政党获胜,获胜的条件是:票数严格大于其他所有政党.求最小代价 题解:暴力枚举其他政党 ...
- CF869E The Untended Antiquity 解题报告
CF869E The Untended Antiquity 题目描述 \(\text{Adieu l'ami}\). Koyomi is helping Oshino, an acquaintance ...
- CMD批处理把txt文本中的每行写入一个新文件,第一列作文件名
需求 现在有一个文件格式如图 ID 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17001 89.84 8.87 1.29 -0.0 0.0 68.99 0.0 0. ...