BZOJ2763[JLOI2011]飞行路线 [分层图最短路]
2763: [JLOI2011]飞行路线
Time Limit: 10 Sec Memory Limit: 128 MB
Submit: 2523 Solved: 946
[Submit][Status][Discuss]
Description
Input
Output
Sample Input
0 4
0 1 5
1 2 5
2 3 5
3 4 5
2 3 3
0 2 100
Sample Output
HINT
对于30%的数据,2<=n<=50,1<=m<=300,k=0;
对于50%的数据,2<=n<=600,1<=m<=6000,0<=k<=1;
对于100%的数据,2<=n<=10000,1<=m<=50000,0<=k<=10.
d[i][j]表示到节点i用了j次免费的最小花费
//
// main.cpp
// bzoj2763
//
// Created by Candy on 9/26/16.
// Copyright © 2016 Candy. All rights reserved.
// #include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <cstring>
using namespace std;
const int N=1e4+,M=5e4+,K=;
inline int read(){
char c=getchar();int x=,f=;
while(c<''||c>''){if(c=='-')f=-;c=getchar();}
while(c>=''&&c<=''){x=x*+c-'';c=getchar();}
return x*f;
}
int n,m,k,s,t,a,b,c;
struct edge{
int v,w,ne;
}e[M<<];
int h[N],cnt=;
inline void ins(int u,int v,int w){
cnt++;
e[cnt].v=v;e[cnt].w=w;e[cnt].ne=h[u];h[u]=cnt;
cnt++;
e[cnt].v=u;e[cnt].w=w;e[cnt].ne=h[v];h[v]=cnt;
}
struct hn{
int u,d,f;
hn(int a=,int b=,int c=):u(a),d(b),f(c){}
bool operator<(const hn &rhs)const{return d>rhs.d;}
};
int d[N][K],done[N][K];
void bfs(){
memset(d,,sizeof(d));
priority_queue<hn> q;
q.push(hn(s,,));
d[s][]=;
while(!q.empty()){
hn x=q.top();q.pop();
int u=x.u,dis=x.d,f=x.f;
if(done[u][f]) continue;
done[u][f]=;
if(u==t){printf("%d",dis);return;}
for(int i=h[u];i;i=e[i].ne){
int v=e[i].v,w=e[i].w;
if(f<k&&!done[v][f+]&&d[v][f+]>dis){
d[v][f+]=dis;
q.push(hn(v,dis,f+));
}
if(!done[v][f]&&d[v][f]>dis+w){
d[v][f]=dis+w;
q.push(hn(v,d[v][f],f));
}
}
}
}
int main(int argc, const char * argv[]) {
n=read();m=read();k=read();s=read();t=read();
for(int i=;i<=m;i++){a=read();b=read();c=read();ins(a,b,c);}
bfs();
return ;
}
BZOJ2763[JLOI2011]飞行路线 [分层图最短路]的更多相关文章
- BZOJ2763: [JLOI2011]飞行路线(分层图 最短路)
题意 题目链接 Sol 分层图+最短路 建\(k+1\)层图,对于边\((u, v, w)\),首先在本层内连边权为\(w\)的无向边,再各向下一层对应的节点连边权为\(0\)的有向边 如果是取最大最 ...
- [bzoj2763][JLOI2011]飞行路线——分层图最短路
水题.不多说什么. #include <bits/stdc++.h> using namespace std; const int maxn = 10010; const int maxk ...
- 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 ...
随机推荐
- EventRay UI Kit – Web & Mobile 的素材
EventRay UI 工具包是一个免费的,可以现成使用的界面套件.包括多个为 Web 和移动应用设计的布局和 UI 元素.所有你需要做的就是下载这个 UI 工具包,点击源码下载打开的页面即可下载. ...
- asp.net+nopi生成Excel遇到设置单元格值null问题
Npoi 生成excel报表功能很不错,功能也不用给大家介绍了.首先看遇到的问题吧! FileStream file = new FileStream(Server.MapPath("Tem ...
- OC单例快速实现
首先新建一个头文件,定义如下宏: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 ...
- Android Action Bar简介
Android Action Bar简介 Design: Action Bar Action Bar是在屏幕顶端的一部分内容,通常在整个app进行中都保持存在. 它提供了几个关键的功能: 1.使得重要 ...
- DirectX标准规定 DirectX和OpenGL的不同
DirectX标准规定 DirectX使用左手坐标系. X轴正向指向右,Y轴正向指向上,Z轴正向垂直纸面向内. 编写Direct3D应用程序时,通常只使用4×4的矩阵和1×4的行向量,相乘时行向量在前 ...
- spring.net (3)依赖注入基础
属性的注入: 在上篇例子中已经出现并解释过: <object id="dog" type="SpringDemo.Dog,SpringDemo" sing ...
- iOS中使用 Reachability 检测网络
iOS中使用 Reachability 检测网络 内容提示:下提供离线模式(Evernote).那么你会使用到Reachability来实现网络检测. 写本文的目的 了解Reachability都 ...
- 【即时通讯】XMPP调试与简单使用
上篇讲了[即时通讯]即时通讯及XMPP概述及环境配置,接下来我们就要进行调试,看看是否可用! 在测试之前我们需要先事先保存一些东西,以便后面使用 —— 登录openfire后台 ——获取服务器名和端口 ...
- 虚拟机安装 Centos6
1 虚拟机安装 Centos6 1.1 前期配置 New Virtual Machine———Typical(典型安装) 选择镜像文件. 设置文件名,用户名和密码. 设置系统在虚拟机软件的名称, 设置 ...
- .NET读写Excel工具Spire.XlS使用(DataExport )
Introduction E-ICEBLUE is developing office.net component, the main products include Spire.Doc, Spir ...