[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 ...
随机推荐
- 从循环里面用QPixmap new对象很耗时联想到的
1.在循环里面用QPixmap new图片对象延迟很高,这个是通过打时间日志得出的,深层原因还不清楚: 2.自制的图片浏览器在初始化的时候会初始化自己的一个图片列表,所以要用到上面的描述.所有图片的初 ...
- 「日常训练」Mike and Feet(Codeforces Round #305 Div. 2 D)
题意 (Codeforces 548D) 对一个有$n$个数的数列,我们要求其连续$x(1\le x\le n)$(对于每个$x$,这样的连续group有若干个)的最小数的最大值. 分析 这是一道用了 ...
- 通过调用API在JavaWeb项目中实现证件识别
本文详细介绍自己如何在JavaWeb项目中通过调用API实现证件识别. 一,Face++使用简介 二,两种方式(图片URL与本地上传)实现证件识别 一,Face++使用简介 Face++旷视人工智能开 ...
- 九度OJ--Q1166
import java.text.DecimalFormat;import java.util.Scanner; /* * 题目描述: * 立方根的逼近迭代方程是 y(n+1) = y(n)*2/3 ...
- MATLAB中矢量场图的绘制 (quiver/quiver3/dfield/pplane) Plot the vector field with MATLAB
1.quiver函数 一般用于绘制二维矢量场图,函数调用方法如下: quiver(x,y,u,v) 该函数展示了点(x,y)对应的的矢量(u,v).其中,x的长度要求等于u.v的列数,y的长度要求等于 ...
- Java判断数字的奇偶
package anli; import java.util.Scanner; public class jiou { public static void main(String[] args){ ...
- 并查集——poj1182(带权并查集高阶)
题目链接:食物链 题解:点击 说一声:这题关系推导值得学习.
- 文本太长,用省略号显示的css样式
——html代码 <divid="d1" title="鼠标放上显示的文字"></div> ——css代码 #d1{ width:300 ...
- Cache的封装和使用
ICache 接口 using System; using System.Collections.Generic; using System.Linq; using System.Text; usin ...
- Winform常用知识总结
Label中的文字自动换行 设置MaximumSize的width为正确的值,设置height为0,设置AutoSize为true. 绘制线条 放置一个Panel,设置size的高度为1,设置Bord ...