当前位置:网站首页>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;
}
边栏推荐
- [0701] [paper reading] allowing data imbalance issue with perforated input during influence
- golang:[]byte转string
- Compile oglpg-9th-edition source code with clion
- Markdown基础语法
- Bubble sort array
- Processing strategy of message queue message loss and repeated message sending
- 以太网PHY层芯片LAN8720A简介
- Reduce -- traverse element calculation. The specific calculation formula needs to be passed in and combined with BigDecimal
- Thread application instance
- 注解开发方式下AutowiredAnnotationBeanPostProcessor的注册时机
猜你喜欢
Excel finds the same value in a column, deletes the row or replaces it with a blank value
数据降维——因子分析
Quanzhi A33 uses mainline u-boot
Use cheat engine to modify money, life and stars in Kingdom rush
IEDA refactor的用法
守望先锋世界观架构 ——(一款好的游戏是怎么来的)
Registration opportunity of autowiredannotationbeanpostprocessor under annotation development mode
End-to-End Object Detection with Transformers(DETR)论文阅读与理解
Educational Codeforces Round 129 (Rated for Div. 2) 补题题解
教程篇(5.0) 10. 故障排除 * FortiEDR * Fortinet 网络安全专家 NSE 5
随机推荐
codeforces每日5题(均1700)-第四天
4274. Suffix expression - binary expression tree
Preprocessing and preprocessing macros
思考变量引起的巨大变化
Windows2008R2 安装 PHP7.4.30 必须 LocalSystem 启动应用程序池 不然500错误 FastCGI 进程意外退出
Chapter 7 - class foundation
Compile oglpg-9th-edition source code with clion
Emmet基础语法
AcWing 1137. 选择最佳线路 题解(最短路)
安装单机redis详细教程
Educational Codeforces Round 129 (Rated for Div. 2) 补题题解
搭建主从模式集群redis
《代码整洁之道》读书笔记
Data dimensionality reduction factor analysis
数字滚动带动画
AcWing 383. 观光 题解(最短路)
Juypter notebook modify the default open folder and default browser
4274. 后缀表达式-二叉表达式树
Getting started with typescript
预处理和预处理宏