当前位置:网站首页>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;
}
边栏推荐
- mysql函数
- Notes de lecture sur le code propre
- Web2.0的巨头纷纷布局VC,Tiger DAO VC或成抵达Web3捷径
- Yunna | why use the fixed asset management system and how to enable it
- What is 9D movie like? (+ common sense of dimension space)
- High frequency interview questions
- 【pytorch学习笔记】Tensor
- PHP asymmetric encryption method private key and public key encryption and decryption method
- Markdown basic grammar
- [pytorch learning notes] tensor
猜你喜欢

Quanzhi A33 uses mainline u-boot
![[paper reading] Ca net: leveraging contextual features for lung cancer prediction](/img/ef/bb48ee88d5dc6fe876a498ab53106e.png)
[paper reading] Ca net: leveraging contextual features for lung cancer prediction

开发固定资产管理系统,开发固定资产管理系统用什么语音
![[error record] problems related to the installation of the shuttle environment (follow-up error handling after executing the shuttle doctor command)](/img/c1/a00425f2e1824a50644c8fbb15fe38.jpg)
[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

云呐|为什么要用固定资产管理系统,怎么启用固定资产管理系统

Windows2008r2 installing php7.4.30 requires localsystem to start the application pool, otherwise 500 error fastcgi process exits unexpectedly

搭建哨兵模式reids、redis从节点脱离哨兵集群

Web2.0的巨头纷纷布局VC,Tiger DAO VC或成抵达Web3捷径
随机推荐
MySQL table historical data cleaning summary
PHP parser badminton reservation applet development requires online system
Golang:[]byte to string
教程篇(5.0) 10. 故障排除 * FortiEDR * Fortinet 網絡安全專家 NSE 5
Educational Codeforces Round 129 (Rated for Div. 2) 补题题解
二进制操作
453-atoi函数的实现
《重构:改善既有代码的设计》读书笔记(上)
[error record] problems related to the installation of the shuttle environment (follow-up error handling after executing the shuttle doctor command)
2022 compilation principle final examination recall Edition
Virtual machine initialization script, virtual machine mutual secret key free
Golang并发编程——goroutine、channel、sync
机器学习笔记 - 时间序列预测研究:法国香槟的月销量
2022.7.1-----leetcode. two hundred and forty-one
搭建哨兵模式reids、redis从节点脱离哨兵集群
AcWing 1131. 拯救大兵瑞恩 题解(最短路)
Registration opportunity of autowiredannotationbeanpostprocessor under annotation development mode
Processing strategy of message queue message loss and repeated message sending
A4988 drive stepper motor "recommended collection"
线程应用实例