【bzoj2763】[JLOI2011]飞行路线 (分层图最短路)(优先队列dij)
【bzoj2763】[JLOI2011]飞行路线
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.
【分析】这是一个分层图最短路的题。题中说对于最短路,其中有k条边可以免费,那么我们就建k层图。对于当前节点,我可以在本层跑,我也可以往上一层,即该条边免费,前提是已经免费的边的条数<k。则用dij即可。
#include <cstdio>
#include <map>
#include <algorithm>
#include <vector>
#include <iostream>
#include <set>
#include <queue>
#include <string>
#include <cstdlib>
#include <cstring>
#include <cmath>
using namespace std;
typedef pair<int,int>pii;
typedef long long LL;
const int N=6e4+;
const int mod=1e9+;
int n,m,s,k,t,cnt,idl[N<<],idr[N<<];
bool vis[N][];
LL d[N][];
vector<pii>edg[N];
struct man{
int v;
int c;
LL w;
bool operator<(const man &e)const{
return w>e.w;
}
};
priority_queue<man>q;
void dij(int s){
memset(d,-,sizeof d);memset(vis,,sizeof vis);
d[s][]=;
q.push(man{s,,});
while(!q.empty()){
int u=q.top().v,c=q.top().c;q.pop(); if(vis[u][c])continue;
vis[u][c]=;
for(int i=;i<edg[u].size();++i){
int v=edg[u][i].first,w=edg[u][i].second;
if(!vis[v][c]&&(d[v][c]==-||d[v][c]>d[u][c]+w)){
d[v][c]=d[u][c]+w;
q.push(man{v,c,d[v][c]});
}
if(c<k){
if(!vis[v][c+]&&(d[v][c+]==-||d[v][c+]>d[u][c])){
d[v][c+]=d[u][c];
q.push(man{v,c+,d[v][c+]});
}
}
}
}
}
int main()
{
int x,y,w;
scanf("%d%d%d",&n,&m,&k);
scanf("%d%d",&s,&t);
while(m--)
{
scanf("%d%d%d",&x,&y,&w);
edg[x].push_back(make_pair(y,w));
edg[y].push_back(make_pair(x,w));
}
dij(s);
LL ans=;
for(int i=;i<=k;i++)ans=min(ans,d[t][i]);
printf("%lld\n",ans);
return ;
}
【bzoj2763】[JLOI2011]飞行路线 (分层图最短路)(优先队列dij)的更多相关文章
- BZOJ2763: [JLOI2011]飞行路线(分层图 最短路)
题意 题目链接 Sol 分层图+最短路 建\(k+1\)层图,对于边\((u, v, w)\),首先在本层内连边权为\(w\)的无向边,再各向下一层对应的节点连边权为\(0\)的有向边 如果是取最大最 ...
- BZOJ2763[JLOI2011]飞行路线 [分层图最短路]
2763: [JLOI2011]飞行路线 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 2523 Solved: 946[Submit][Statu ...
- [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 ...
随机推荐
- 【题解】SCOI2009围豆豆
很久之前就很想做的一道题,一直思考到今天才下定决心看题解.这道题中,很关键的一点就在于:如何判断一个点是否在一个多边形内?其实如果计算几何基本功扎实的话,应该是可以很快给出答案的(可惜我完全不行):由 ...
- 安徽师大附中%你赛day3T1 怜香惜玉 解题报告
怜香惜玉 题意: 已知 \(f(x)=\frac{2 \times \sum_{(i,x)=1}^x i}{φ(x)}\) 先给定数据组数\(t\)和\(k\) 每组数据给出\(n\),求\(\sum ...
- win10 update orchestratorservere禁用
1 Windows 10系统中有一项Update Orchestrator Service(更新协调器办事),在当地办事窗口中,我们发现 Update Orchestrator Service 办 ...
- readelf用法小记
By francis_hao Feb 14,2017 显示ELF文件的信息 用法概述 readelf和objdump类似,不过,readelf会显示更详细的信息,而且独立于BFD库,因此当BFD ...
- ng父组件调用子组件的方法
https://www.pocketdigi.com/20170204/1556.html 组件之间方法的调用统一用中间人调用.数据传递直接input和output即可
- php SPL四种常用的数据结构
1.栈[先进后出] $stack = new SplStack(); $stack->push('data1'); $stack->push('data2'); $stack->pu ...
- nginx实时生成缩略图到硬盘上
现在随着各终端的出现(手机,ipad等平板),以及各种终端的手机分辨率和尺寸都不同,现在手机用户流量都是宝,网上出现了各种各样的生成缩略图功能的架构,有使用php实时生成缩略图的,也有用nginx + ...
- poj3580 序列之王 fhqtreap
fhqtreap的写法 操作其实都差不多哇 #include<cstdio> #include<cstring> #include<algorithm> using ...
- 【STSRM12】整除
[题意]给定长度为n的序列A,求最长的区间满足区间内存在数字能整除区间所有数字,同时求所有方案.n<=5*10^5,Ai<2^31. [算法]数论??? [题解]首先一个区间的基准数一定是 ...
- MyBatis系列三 之 使用getMapper剔除掉Dao的实现类
MyBatis系列三 之 使用getMapper剔除掉Dao的实现类 我们在系列一 中 我们使用的是Dao的实现类 来操作底层数据库,今天我们使用getMapper()来替换Dao的实现类, ...