-
Notifications
You must be signed in to change notification settings - Fork 0
/
dijkstra-heap.cpp
37 lines (33 loc) · 999 Bytes
/
dijkstra-heap.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/* Author: NogiNonoka
Date: 2021.1.13
Time Complexity: O(ElogV) */
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const int MAXN = 1007;
struct Dijkstra_Heap {
int n;
int s, t;
vector<pair<int, int>> graph[MAXN];
int dis[MAXN];
void dijkstra() {
priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> que;
dis[s] = 0;
que.push({dis[s], s});
while (!que.empty()) {
int now = que.top().second;
int tmpval = que.top().first;
que.pop();
if (dis[now] < tmpval) continue;
for (int i = 0; i < graph[now].size(); i++) {
int nxt = graph[now][i].first;
int val = graph[now][i].second;
if (dis[nxt] > val + dis[now]) {
dis[nxt] = val + dis[now];
que.push({dis[nxt], nxt});
}
}
}
return;
}
} djk;