当前位置:网站首页>AcWing 1137. Select the best line solution (the shortest circuit)
AcWing 1137. Select the best line solution (the shortest circuit)
2022-07-02 19:32:00 【Mr. Qiao Da】
AcWing 1137. Select the best route
Their thinking : Each starting point will run once, and the shortest circuit will timeout , Then establish a virtual starting point , The distance between this initial point and all starting points is 0, So the shortest path from the virtual starting point to the end point is the shortest and shortest path among all the starting points
#include<bits/stdc++.h>
using namespace std;
const int N = 1010, M = 40010, INF = 0x3f3f3f3f;
int n, m, T;
int h[N], e[M], ne[M], w[M], idx;
int d[N];
int q[N];
bool st[N];
void add(int a, int b, int c){
e[idx] = b;
w[idx] = c;
ne[idx] = h[a];
h[a] = idx ++ ;
}
int spfa(){
memset(d, 0x3f, sizeof d);
int hh = 0, tt = 1;
q[0] = 0;
d[0] = 0;
st[0] = true;
while(tt != hh){
int t = q[hh ++ ];
if(hh == N) hh = 0;
st[t] = false;
for(int i = h[t]; ~i; i = ne[i]){
int j = e[i];
if(d[j] > d[t] + w[i]){
d[j] = d[t] + w[i];
if(!st[j]){
q[tt ++ ] = j;
if(tt == N) tt = 0;
st[j] = true;
}
}
}
}
if(d[T] > 1e9) return -1;
else return d[T];
}
int main()
{
while(scanf("%d%d%d", &n, &m, &T) != -1){
memset(h, -1, sizeof h);
idx = 0;
while(m -- ){
int a, b, c;
scanf("%d%d%d", &a, &b, &c);
add(a, b, c);
}
int w;
cin>>w;
while(w -- ){
int ver;
scanf("%d", &ver);
add(0, ver, 0);
}
cout<<spfa()<<endl;
}
return 0;
}
边栏推荐
- A4988驱动步进电机「建议收藏」
- 450-深信服面经1
- Web2.0的巨头纷纷布局VC,Tiger DAO VC或成抵达Web3捷径
- End to end object detection with transformers (Detr) paper reading and understanding
- 潇洒郎:彻底解决Markdown图片问题——无需上传图片——无需网络——转发给他人图片无缺失
- The mybatieshelperpro tool can be generated to the corresponding project folder if necessary
- 教程篇(5.0) 10. 故障排除 * FortiEDR * Fortinet 網絡安全專家 NSE 5
- MySQL
- MySQL表历史数据清理总结
- MySQL高级(进阶)SQL语句
猜你喜欢
Idea editor removes SQL statement background color SQL statement warning no data sources are configured to run this SQL And SQL dialect is not config
为什么要做企业固定资产管理系统,企业如何加强固定资产管理
Machine learning notes - time series prediction research: monthly sales of French champagne
注解开发方式下AutowiredAnnotationBeanPostProcessor的注册时机
Watchful pioneer world outlook Architecture - (how does a good game come from)
Compile oglpg-9th-edition source code with clion
[error record] problems related to the installation of the shuttle environment (follow-up error handling after executing the shuttle doctor command)
Yolov3 trains its own data set to generate train txt
How performance testing creates business value
Registration opportunity of autowiredannotationbeanpostprocessor in XML development mode
随机推荐
股票证券公司排名,有安全保障吗
Registration opportunity of autowiredannotationbeanpostprocessor in XML development mode
xml开发方式下AutowiredAnnotationBeanPostProcessor的注册时机
C文件输入操作
Data dimensionality reduction factor analysis
Processing strategy of message queue message loss and repeated message sending
Horizontal ultra vires and vertical ultra vires [easy to understand]
IEDA refactor的用法
LeetCode 0871.最低加油次数 - 类似于POJ2431丛林探险
搭建主从模式集群redis
AcWing 341. 最优贸易 题解 (最短路、dp)
End to end object detection with transformers (Detr) paper reading and understanding
《重构:改善既有代码的设计》读书笔记(上)
Memory management of C
"Patient's family, please come here" reading notes
A4988 drive stepper motor "recommended collection"
AcWing 1129. 热浪 题解(最短路—spfa)
Introduction of Ethernet PHY layer chip lan8720a
What is 9D movie like? (+ common sense of dimension space)
Data dimensionality reduction principal component analysis