当前位置:网站首页>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);
}
边栏推荐
- Pcb|about FPC reinforcement type
- 电子学:第009课——实验 7:研究继电器
- Application of can optical transceiver of ring network redundant can/ optical fiber converter in fire alarm system
- Introduction to the main functions of the can & canfd comprehensive test and analysis software lkmaster of the new usbcan card can analyzer
- 洛谷P2839 [国家集训队]middle(二分 + 主席树 + 区间合并)
- 电子学:第012课——实验 11:光和声
- Take you through the normalization flow of GaN
- RMQ区间最大值下标查询,区间最值
- Electronics: Lesson 012 - Experiment 13: barbecue LED
- How to create a new branch with SVN
猜你喜欢
共话云原生数据库的未来
TCP的那点玩意儿
Opencv minimum filtering (not limited to images)
Electronics: Lesson 010 - Experiment 8: relay oscillator
基于STM32MP157调试MIPI-DSI屏幕
Apache CouchDB 代码执行漏洞(CVE-2022-24706 )批量POC
Machine learning notes linear regression of time series
电子学:第008课——实验 6:非常简单的开关
Electronics: Lesson 012 - Experiment 13: barbecue LED
C disk drives, folders and file operations
随机推荐
Luogu p2839 [national training team]middle (two points + chairman tree + interval merging)
洛谷P2839 [国家集训队]middle(二分 + 主席树 + 区间合并)
挖掘微生物暗物质——新思路
Three Siemens fire-fighting hosts fc18 are equipped with can optical transceiver for optical fiber redundant ring network networking test
1742. maximum number of small balls in the box
50. pow (x, n) - fast power
基于RBAC 的SAAS系统权限设计
电子学:第014课——实验 15:防入侵报警器(第一部分)
电子学:第012课——实验 13:烧烤 LED
力扣 272. 最接近的二叉搜索树值 II 递归
@The difference between resource and @autowired annotation, why recommend @resource?
Electronics: Lesson 012 - Experiment 11: light and sound
【莫比乌斯反演】
Est - il sûr d'ouvrir un compte d'actions maintenant via le lien d'ouverture de compte coiffé?
唐老师讲运算放大器(第七讲)——运放的应用
时钟刻度盘的绘制
Pychart's wonderful setting: copy immediately after canceling the comment and bring #
[Video] ffplay uses MJPEG format to play USB camera
使用Adobe Acrobat Pro调整PDF页面为统一大小
The fourth floor is originally the fourth floor. Let's have a look