当前位置:网站首页>Niuke: flight route (layered map + shortest path)
Niuke: flight route (layered map + shortest path)
2022-06-25 08:02:00 【Mfy's little brother 1】
Cattle guest : Flight path ( Hierarchical graph + shortest path )
The question :
A graph with edge weights , Seek from s To t The shortest distance , You can ignore k The weight of the edge .
2 < = n < = 10000 , 1 < = m < = 50000 , 0 < = k < = 10 2<=n<=10000,1<=m<=50000,0<=k<=10 2<=n<=10000,1<=m<=50000,0<=k<=10
Ideas :
because k Very small , Think about it No To the hierarchical graph , Think of the original as k layer , Each floor is exactly the same , Build new edges to connect each floor , For the first layer from x To y, hold x The point corresponding to each layer and the point corresponding to the next layer y Even one weight is zero 0 The edge of , hold y The point corresponding to each layer and the point corresponding to the next layer x Even one weight is zero 0 The edge of . So from a certain floor x To the next floor y It means you used it once k
Run the shortest path again
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF=0x3f3f3f3f;
typedef pair<int,int>pii;
const int maxn=3e6+5;
int s,n,m,t,k,d,dis[maxn],vis[maxn],head[maxn],w[maxn],to[maxn],nex[maxn];
void add(int x,int y,int z){
nex[++d]=head[x];
to[d]=y;
w[d]=z;
head[x]=d;
}
void dij(){
memset(dis,INF,sizeof(dis));
dis[s]=0;
priority_queue<pii,vector<pii>,greater<pii>>p;
p.push({
0,s});
while(!p.empty()){
int x=p.top().second;
p.pop();
if(vis[x])continue;
vis[x]=1;
for(int i=head[x];i;i=nex[i]){
int y=to[i];
if(dis[y]>dis[x]+w[i]){
dis[y]=dis[x]+w[i];
p.push({
dis[y],y});
}
}
}
}
int main(){
scanf("%d%d%d%d%d",&n,&m,&k,&s,&t);
for(int i=1,x,y,z;i<=m;i++){
scanf("%d%d%d",&x,&y,&z);
add(x,y,z),add(y,x,z);
for(int j=1;j<=k;j++){
add(x+j*n,y+j*n,z);
add(y+j*n,x+j*n,z);
add(x+(j-1)*n,y+j*n,0);
add(y+(j-1)*n,x+j*n,0);
}
}
dij();
int ans=INF;
for(int i=0;i<=k;i++){
ans=min(ans,dis[i*n+t]);
}
printf("%d\n",ans);
}
边栏推荐
- 电子学:第010课——实验 8:继电振荡器
- bat启动.NET Core
- Basic use of ActiveMQ in Message Oriented Middleware
- The fourth floor is originally the fourth floor. Let's have a look
- 将数据导入到MATLAB
- Requirements for Power PCB circuit board design 2021-11-09
- Electronics: Lesson 010 - Experiment 8: relay oscillator
- MySQL simple permission management
- Tips on how to design soft and hard composite boards ~ 22021/11/22
- 基于RBAC 的SAAS系统权限设计
猜你喜欢
随机推荐
Dietary intervention reduces cancer treatment-related symptoms and toxicity
电子学:第013课——实验 14:可穿戴的脉冲发光体
洛谷P5994 [PA2014]Kuglarz(异或思维+MST)
电子学:第010课——实验 8:继电振荡器
@The difference between resource and @autowired annotation, why recommend @resource?
Requirements for Power PCB circuit board design 2021-11-09
Atlas conflict Remote Code Execution Vulnerability (cve-2022-26134 vulnerability analysis and protection
Six causes of PCB disconnection 2021-10-20
产品经理专业知识50篇(四)-从问题到能力提升:AMDGF模型工具
基于RBAC 的SAAS系统权限设计
现在通过开户经理发的开户链接股票开户安全吗?
深度学习系列45:图像恢复综述
2021ICPC网络赛第一场
[deep learning lightweight backbone] 2022 edgevits CVPR
剑指offer刷题(简单等级)
420-二叉树的层序遍历2(429. N 叉树的层序遍历、515.在每个树行中找最大值、116.填充每个节点的下一个右侧节点指针、104.二叉树的最大深度、111.二叉树的最小深度)
电子学:第014课——实验 15:防入侵报警器(第一部分)
飞机引气系统的建模与故障仿真
Application of can optical transceiver of ring network redundant can/ optical fiber converter in fire alarm system
C disk drives, folders and file operations









