bzoj 2763: [JLOI2011]飞行路线 分层图
n个点m条路, 每条路有权值, 给出起点和终点, 求一条路使得权值最小。可以使路过的路中, k条路的权值忽略。
其实就是多一维, 具体看代码
#include<bits/stdc++.h>
using namespace std;
#define pb(x) push_back(x)
#define ll long long
#define mk(x, y) make_pair(x, y)
#define lson l, m, rt<<1
#define mem(a) memset(a, 0, sizeof(a))
#define rson m+1, r, rt<<1|1
#define mem1(a) memset(a, -1, sizeof(a))
#define mem2(a) memset(a, 0x3f, sizeof(a))
#define rep(i, a, n) for(int i = a; i<n; i++)
#define ull unsigned long long
typedef pair<int, int> pll;
const double PI = acos(-1.0);
const double eps = 1e-;
const int mod = 1e9+;
const int inf = ;
const int dir[][] = { {-, }, {, }, {, -}, {, } };
const int maxn = 5e4+;
int dis[][], in[][], num, head[maxn*];
int n, m, k, s, t;
struct edge
{
int to, nextt, w;
}e[maxn*];
struct node
{
int u, x;
node(){}
node(int u, int x):u(u),x(x){}
};
void init() {
mem1(head);
num = ;
}
void add(int u, int v, int w) {
e[num].to = v;
e[num].nextt = head[u];
e[num].w = w;
head[u] = num++;
}
queue <node> q;
int dij() {
mem2(dis);
q.push(node(s, ));
dis[][s] = ;
in[][s] = ;
while(!q.empty()) {
node tmp = q.front(); q.pop();
int u = tmp.u, x = tmp.x;
in[x][u] = ;
for(int i = head[u]; ~i; i = e[i].nextt) {
int v = e[i].to;
if(dis[x][v]>dis[x][u]+e[i].w) {
dis[x][v] = dis[x][u]+e[i].w;
if(!in[x][v]) {
in[x][v] = ;
q.push(node(v, x));
}
}
}
if(x<k) {
x++;
for(int i = head[u]; ~i; i = e[i].nextt) {
int v = e[i].to;
if(dis[x][v]>dis[x-][u]) {
dis[x][v] = dis[x-][u];
if(!in[x][v]) {
in[x][v] = ;
q.push(node(v, x));
}
}
}
}
}
int ans = inf;
for(int i = ; i<=k; i++)
ans = min(ans, dis[i][t]);
return ans;
}
int main()
{
int x, y, z;
cin>>n>>m>>k>>s>>t;
init();
while(m--) {
scanf("%d%d%d", &x, &y, &z);
add(x, y, z);
add(y, x, z);
}
int ans = dij();
cout<<ans<<endl;
return ;
}
bzoj 2763: [JLOI2011]飞行路线 分层图的更多相关文章
- bzoj 2763: [JLOI2011]飞行路线 -- 分层图最短路
2763: [JLOI2011]飞行路线 Time Limit: 10 Sec Memory Limit: 128 MB Description Alice和Bob现在要乘飞机旅行,他们选择了一家相 ...
- bzoj 2763 [JLOI2011]飞行路线——分层图
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=2763 分层图两种方法的练习. 1.把图分成k+1层,本层去上面一层的边免费.但空间时间都不算 ...
- Bzoj 2763: [JLOI2011]飞行路线 拆点,分层图,最短路,SPFA
2763: [JLOI2011]飞行路线 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 1694 Solved: 635[Submit][Statu ...
- 分层图+最短路算法 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 ...
- BZOJ 2763: [JLOI2011]飞行路线 【分层图模板】
任意门:https://www.lydsy.com/JudgeOnline/problem.php?id=2763 2763: [JLOI2011]飞行路线 Time Limit: 10 Sec M ...
- bzoj2763: [JLOI2011]飞行路线(分层图spfa)
2763: [JLOI2011]飞行路线 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 3234 Solved: 1235[Submit][Stat ...
- BZOJ2763[JLOI2011]飞行路线 [分层图最短路]
2763: [JLOI2011]飞行路线 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 2523 Solved: 946[Submit][Statu ...
- BZOJ 2763: [JLOI2011]飞行路线 最短路
2763: [JLOI2011]飞行路线 Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://www.lydsy.com/JudgeOnline/pr ...
随机推荐
- UML的基本图(一)
A class diagram shows a set of classes, interfaces, and collaborations and their relationships. T ...
- 从零开始学习UNITY3D(GUI篇 群组视图控件)
控件组可以看成一个大的容器,控件组里面的控件,相对位置已该控件组为基准,而不再已屏幕左上角为基准. 下面来看一下代码实例及其效果截图: public class GUI2 : MonoBehaviou ...
- 算法精解(C语言描述) 第4章 读书笔记
第4章 算法分析 1.最坏情况分析 评判算法性能的三种情况:最佳情况.平均情况.最坏情况. 为何要做最坏情况分析: 2.O表示法 需关注当算法处理的数据量变得无穷大时,算法性能将趋近一个什么样的值.一 ...
- 2014.8.20break,continue,字符串,数字和日期
(一)break与continue break——彻底终断循环 continue——中断本次循环,继续下次循环 break举例: //求100以内所有质数 ; i <= ; i++) { ;// ...
- Windows Server 2003 安装Sql Server 2005 问题处理
安装途中遇到: 问题1.无法找到产品Microsoft SQL Server Native Client的安装程序包.请使用安装包sqlncli.msi的有效副本重新安装? 答:安装SQL Serve ...
- RPC介绍以及编程
1 RPC介绍 RPC(Remote Procedure Call Protocol)——远程过程调用协议,它是一种通过网络从远程计算机程序上请求服务,而不需要了解底层网络技术的协 议. RPC采用客 ...
- Jsp连接Mysql数据库取数方法
我将Jsp连接Mysql数据库方法整理如下,供大家学习交流! 1.首先在myslq数据库中新建mldn数据库,并新建emp表.(方法不展开介绍) 插入数据如下: create table `emp` ...
- qt检测网络连接状态【只能检测和路由器的连接,不能测试到外网的连接】
#include <QCoreApplication>#include <QDebug>#include <QTextStream>#include <QDi ...
- struts1标签(html:text)
这个标签可能是出现频率最高的标签了. 功能: <html:text/>产生HTML语句: <input type=”text”…> 也就是在页面上产生input类型的显示标签. ...
- symfony2-不同bundle的entity的一对多关系
重点:其实和普通一个bundle中一样,只是把entity地址写全就行. 例子: 表commentone (多方) 表shopone(一方) 在Userbundle中的Commentone实体对应关系