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 ...
随机推荐
- The "Run One Program Only" Phenomenon
As previously discussed,embedded devices normally embody the functionality they implement.In other w ...
- Android TXT文件读写
package com.wirelessqa.helper; import java.io.FileInputStream; import java.io.FileOutputStream; impo ...
- html基础标签-2-textarea文本域
textarea文本域 <!doctype html> <html lang='zh-cn'> <head> <meta charset='utf-8'> ...
- vs2012新建项目产生的问题
当用vs新建web项目时遇到
- VS快捷方式小技巧
VS2005代码编辑器的展开和折叠代码确实很方便和实用.以下是展开代码和折叠代码所用到的快捷键,很常用: Ctrl + M + O: 折叠所有方法 Ctrl + M + M: 折叠或者展开当前方法 C ...
- 创建oracle数据库的表空间、用户、目录、导入\导出文件等信息
1.创建表空间 create tablespace ts_aw logging datafile 'd:\app\Administrator\product\tablespace\ts_aw.dbf' ...
- 浅谈SpringMVC(二)
一.SpringMVC的拦截器 1.写类implements HandlerInterceptor public class MyMvcInterceptor implements HandlerIn ...
- vs2012C#编程环境设置智能提示
vs2012 智能提示和 显示行号的问题 路径为 菜单里 工具-->选项-->文本编辑器-->C# 如图所示 自动列出成员就是 vs里面的智能提示 行号就会显示所写代码的行 ...
- HiveQL与SQL区别
转自:http://www.aboutyun.com/thread-7327-1-1.html 1.Hive不支持等值连接 SQL中对两表内联可以写成:select * from dual a,dua ...
- python中,str和repr的区别
str函数,它会把值转换为合理形式的字符串,以便用户可以理解. repr会创建一个字符串,它以合法的Python表达式的形式来表示值. 例如: >>> print repr(&quo ...