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 ...
随机推荐
- NodeBB – 基于 Node.js 的开源论坛系统
NodeBB 是一个更好的论坛平台,专门为现代网络打造.它是免费的,易于使用. NodeBB 论坛软件是基于 Node.js 开发,支持 Redis 或 MongoDB 的数据库.它利用 Web So ...
- 自己动手打造WEB服务器 Windows + Apache + PHP + MySQL
XWAMP并不打算打造一个多功能,零配置,方便调试的工具.XWAMP只是把原程序简单的组合在一起,利用CMD命令控制,真正的绿色版,只为了多学习点Windows + Apache + PHP + My ...
- JavaScript学习笔记-实现枚举类型,扑克牌应用
//实现枚举类型,扑克牌应用 function creatEnum(p){ //构造函数 var Enumeration = function(){throw 'can not Ins ...
- WinForm-GridView
前端: <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="CKXM.aspx. ...
- Urban Planning and Public Health - Reflection on Professor Webster's article in Urban Planning Forum
1. General review. Professor Webster published this article in Urban Planning Forum, one of the top ...
- [Android]解决ClickableSpan中点击后ListView中item的长按冲突的问题
以下内容为原创,转载请注明: 来自天天博客:http://www.cnblogs.com/tiantianbyconan/p/3823429.html 项目中碰到一个问题,情景是这样的: 有一个Lis ...
- 经典的Java基础面试题集锦
经典的Java基础面试题集锦,欢迎收藏和分享. 问题:如果main方法被声明为private会怎样? 答案:能正常编译,但运行的时候会提示”main方法不是public的”. 问题:Java里的传引用 ...
- 监听SD卡状态
最近在做项目时遇到需要处理SD卡拔出时的监听,在网上找了很多资料.总结了一下, 用接收广播处理最有效率 sd卡拔插时会发送广播,具体如下(摘自一位大虾的博客 来自:http://blog. ...
- NSArray与NSMutableArray 数组与可变数组
1.NSArray 是一个父类,NSMUtableArray是其子类,他们构成了OC的数组.2.NSArray的创建NSArray * array = [[NSArray alloc]initWith ...
- iOS--XML三种解析方法( XMLDictionary)、(GDataXMLNode)、(NSXMLParser)
iOS9之后,默认网络请求是https,所有我们要设置一下网络安全,具体设置如下 1.第三方类库 XMLDictionary 下载地址: https://github.com/nicklockwood ...