-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdijkstra.cpp
More file actions
59 lines (47 loc) · 976 Bytes
/
Copy pathdijkstra.cpp
File metadata and controls
59 lines (47 loc) · 976 Bytes
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include <iostream>
#include <fstream>
#include <algorithm>
#include <string>
#include <cstring>
#include <map>
#include <vector>
#include <cmath>
#include <bitset>
#include <set>
#include <queue>
#include <complex>
#include <functional>
#define mp make_pair
#define pb push_back
typedef long long ll;
typedef long double ld;
using namespace std;
// solution starts here
#define N 100100
#define INF 1e18
int pre[N];
vector<pair<int, int> > g[N];
ll dist[N];
void dijkstra(int source, int sink){
for(int i=0; i<N; i++) dist[i] = INF;
priority_queue<pair<ll,int> > pq;
pre[source] = source;
dist[source] = 0;
pq.push(mp(0,source));
while(pq.size()){
int vert = pq.top().second; pq.pop();
for(pair<int,int>& edge : g [vert]){
int nei = edge.second;
ll w = edge.first;
ll tent = dist[vert] + w;
if(dist[nei] > tent){
dist[nei] = tent;
pre[nei] = vert;
pq.push(mp(-dist[nei], nei));
}
}
}
}
int main(){
return 0;
}