当前位置:网站首页>(dijkstra+ shortest path + edge traversal 0 (m)) acwing 850 Dijkstra finding the shortest path II
(dijkstra+ shortest path + edge traversal 0 (m)) acwing 850 Dijkstra finding the shortest path II
2022-06-13 09:24:00 【Age worry】
850. Dijkstra Find the shortest path II
Topic link https://www.acwing.com/problem/content/852/
subject :
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<vector>
#include<utility>
#include<queue>
using namespace std;
const int N=2e5+10;
int n,m;
bool vis[N];
vector<pair<int ,int > > a[N];
int dijkstra(){
priority_queue<pair<int ,int > ,vector<pair<int ,int >> ,greater<pair<int ,int >>> q;
q.push({
0,1});
bool flag=0;
int sum=0;
while(q.size()){
auto tmp=q.top();
q.pop();
if(vis[tmp.second]) continue;
vis[tmp.second]=1;
if(tmp.second==n){
flag=1;
sum=tmp.first;
}
for(int i=0;i<a[tmp.second].size();i++){
if(!vis[a[tmp.second][i].first]){
q.push({
tmp.first+a[tmp.second][i].second,a[tmp.second][i].first});
}
}
}
if(flag) return sum;
return -1;
}
int main(){
cin>>n>>m;
int x,y,z;
for(int i=0;i<m;i++){
scanf("%d%d%d",&x,&y,&z);
a[x].push_back({
y,z});
}
cout<<dijkstra();
return 0;
}
边栏推荐
- Haproxy + keepalived for high availability load balancing of MySQL
- How Simulink adds modules to the library browser
- Can the operation of the new BMW I3 meet the expectations of the famous products of the 3 series?
- Jenkins接入Openldap用戶認證
- 静态变量与一个类相关联,只要该类在内存中(只要您的应用程序终止,该变量就不存在)就可以使用。(堆本体,栈引用)
- LeetCode 6097. Match after replacing characters (Dictionary)
- C language 7-13 day K candle chart (15 points)
- LeetCode 6096. Success logarithm of spells and potions (binary search)
- LeetCode 1143. 最长公共子序列
- Solov2 source code analysis
猜你喜欢

How Simulink adds modules to the library browser

(dp+ memory) acwing 901 skiing

Final principle

Class loading overview

C language: minesweeping

Heap

C language: Simulated Implementation of library function strcpy

Exploitation of competitive loopholes in attacking and defending world PWN play conditions
![1-2 24:00 (20 points) [CSP certification true question]](/img/3b/fe2c0e46dca604e5906d9c5ceabbe3.jpg)
1-2 24:00 (20 points) [CSP certification true question]

线上调试工具Arthas基础
随机推荐
20211020 academician all drive system
Exporting MySQL data table documents using Navicat
Z字形变换
(tree DP) acwing 285 A dance without a boss
LeetCode 72. 编辑距离
Cisco, Huawei network equipment
JUC 字段更新器
马斯克的「元宇宙」梦
Simulink variant model and variant subsystem usage
LeetCode 72. Edit distance
Lecture par lots de tous les fichiers vocaux sous le dossier
C language: minesweeping
20211006 linear transformation
Final principle
Simple use of spiel expressions
I have summarized the knowledge points of JS [intermediate and advanced] for you
LeetCode 322. Change
Remember! Don't be too confident in writing code! Be sure to write some key log info output, or the problem will not be located.
C language: file operation
JS【中高级】部分的知识点我帮你们总结好了