当前位置:网站首页>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;
}
边栏推荐
- End-to-End Object Detection with Transformers(DETR)论文阅读与理解
- AcWing 341. 最优贸易 题解 (最短路、dp)
- Quanzhi A33 uses mainline u-boot
- Fastdfs installation
- MySQL
- Use cheat engine to modify money, life and stars in Kingdom rush
- Yunna | why use the fixed asset management system and how to enable it
- Windows2008R2 安装 PHP7.4.30 必须 LocalSystem 启动应用程序池 不然500错误 FastCGI 进程意外退出
- Windows2008r2 installing php7.4.30 requires localsystem to start the application pool, otherwise 500 error fastcgi process exits unexpectedly
- IDEA编辑器去掉sql语句背景颜色SQL语句警告No data sources are configured to run this SQL...和SQL Dialect is Not Config
猜你喜欢

开发固定资产管理系统,开发固定资产管理系统用什么语音

Yunna | why use the fixed asset management system and how to enable it

线程应用实例

Use cheat engine to modify money, life and stars in Kingdom rush

Web2.0的巨头纷纷布局VC,Tiger DAO VC或成抵达Web3捷径
![[0701] [paper reading] allowing data imbalance issue with perforated input during influence](/img/c7/9b7dc4b4bda4ecfe07aec1367fe059.png)
[0701] [paper reading] allowing data imbalance issue with perforated input during influence

Markdown basic grammar

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

Refactoring: improving the design of existing code (Part 1)

What is 9D movie like? (+ common sense of dimension space)
随机推荐
How to print mybats log plug-in using XML file
Chic Lang: completely solve the problem of markdown pictures - no need to upload pictures - no need to network - there is no lack of pictures forwarded to others
安装单机redis详细教程
Chapter 7 - class foundation
AcWing 1129. 热浪 题解(最短路—spfa)
《重构:改善既有代码的设计》读书笔记(上)
Virtual machine initialization script, virtual machine mutual secret key free
AcWing 342. 道路与航线 题解 (最短路、拓扑排序)
2022.7.1-----leetcode.241
Date tool class (updated from time to time)
高级性能测试系列《24. 通过jdbc执行sql脚本》
MySQL
Gamefi chain game system development (NFT chain game development function) NFT chain game system development (gamefi chain game development source code)
Codeworks 5 questions per day (1700 average) - day 4
Notes de lecture sur le code propre
Registration opportunity of autowiredannotationbeanpostprocessor in XML development mode
Golang:[]byte to string
预处理和预处理宏
golang:[]byte转string
PHP parser badminton reservation applet development requires online system