题目链接

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]飞行路线 分层图的更多相关文章

  1. bzoj 2763: [JLOI2011]飞行路线 -- 分层图最短路

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

  2. bzoj 2763 [JLOI2011]飞行路线——分层图

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=2763 分层图两种方法的练习. 1.把图分成k+1层,本层去上面一层的边免费.但空间时间都不算 ...

  3. Bzoj 2763: [JLOI2011]飞行路线 拆点,分层图,最短路,SPFA

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

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

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

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

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

  6. BZOJ 2763: [JLOI2011]飞行路线 【分层图模板】

    任意门:https://www.lydsy.com/JudgeOnline/problem.php?id=2763 2763: [JLOI2011]飞行路线 Time Limit: 10 Sec  M ...

  7. bzoj2763: [JLOI2011]飞行路线(分层图spfa)

    2763: [JLOI2011]飞行路线 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 3234  Solved: 1235[Submit][Stat ...

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

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

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

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

随机推荐

  1. cmd命令 拷贝某文件夹及其子文件夹文件到其它文件夹

    @ECHO OFF cd/d %H:\FileLoc\CNET&cd.. ::echo 拷贝"%H:\FileLoc\CNET"中文件到"H:\FileLocTe ...

  2. 推荐两个不错的CAD二次开发(.Net)手册

    推荐两个不错的CAD二次开发(.Net)手册 http://www.mjtd.com/helpcenter/netguide/index.html http://www.ceesky.com/book ...

  3. 前端新人学习笔记-------html/css/js基础知识点(二)

    4月7日学到的知识点:     一:<img src="1.png" alt="美女"/> alt是给图片添加介绍,当图片没加载出来时,会直接显示a ...

  4. 队列的实现 -- 数据结构与算法的javascript描述 第五章

    队列也是列表的一种,有不同于列表的规则. 先进先出 入队方法 出队方法 可以找到队首 可以找到队尾 可以查看队列有多长 可以查看队列是否为空 这是一个基本的需求,围绕他来实现,当然我们可以自己扩展列表 ...

  5. JavaScript之JS的执行环境和作用域

    一.执行环境是JavaScript中最为重要的一个概念.执行环境定义了变量或函数有权访问的其他数据,决定了他们各自的行为,每个执行环境都有一个与之关联的变量对象(variable object),环境 ...

  6. java中Log4J的使用笔记

    使用Log4J,程序员可以控制日志信息输送的目的地,包括控制台,文件,GUI组件和NT事件记录器,也可以控制每一条日志的输出格式,或通过定义每一条日志信息的级别,更加细致地控制日志的生成过程. Log ...

  7. Deep Learning(深度学习)学习笔记整理系列之(八)

    Deep Learning(深度学习)学习笔记整理系列 zouxy09@qq.com http://blog.csdn.net/zouxy09 作者:Zouxy version 1.0 2013-04 ...

  8. android 文件操作类简易总结

    android 文件操作类(参考链接) http://www.cnblogs.com/menlsh/archive/2013/04/02/2997084.html package com.androi ...

  9. JavaScript中的构造函数

    目录: constructor & prototype 为构造函数添加属性和方法的多种不同方法 组合使用this和prototype关键字创建构造函数(常用方法) 用对象直接量作为构造函数的参 ...

  10. [C#技术参考]Socket传输结构数据

    最近在做一个机器人项目,要实时的接收机器人传回的坐标信息,并在客户端显示当前的地图和机器人的位置.当然坐标的回传是用的Socket,用的是C++的结构体表示的坐标信息.但是C#不能像C++那样很eas ...