-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathdijkstras.sublime-snippet
More file actions
executable file
·38 lines (36 loc) · 1.06 KB
/
dijkstras.sublime-snippet
File metadata and controls
executable file
·38 lines (36 loc) · 1.06 KB
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
<snippet>
<content><![CDATA[
template <typename T>
using minpq = priority_queue<T, vector<T>, greater<T>>;
const long long inf = (long long) (1e18);
void dijkstra(int S){
long long u , vv , c , w;
minpq<pair<long long, long long>> Q;
fill(dist.begin(), dist.end(), inf);
Q.push({0,S});
dist[S] = 0;
while(!Q.empty()){
u = Q.top().second;
c = Q.top().first;
Q.pop();
if(dist[u] < c){
continue;
}
for(int i = 0 ; i < (int) G[u].size() ; i++){
w = G[u][i].first;
vv = G[u][i].second;
if(dist[vv] > dist[u] + w){
dist[vv] = dist[u] + w;
Q.push({dist[vv],vv});
}
}
}
}
]]></content>
<!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
<tabTrigger>dijkstra</tabTrigger>
<!-- Optional: Set a scope to limit where the snippet will trigger -->
<scope>source.cpp, source.c++, source.c</scope>
<!-- Optional: Description to show in the menu -->
<description>Dijkstra's (SSSP) Single Source Shortest Path Algo</description>
</snippet>