Advertisement
Guest User

Untitled

a guest
Feb 29th, 2020
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.55 KB | None | 0 0
  1. void Dijkstra (int s) {
  2.     vector < int > dist(n, INF);
  3.     dist[s] = 0;
  4.     set < pair < int , int > > st;
  5.     st.insert({0, s});
  6.     while (!st.empty()) {
  7.         auto e = *st.begin();
  8.         int v = e.first;
  9.         int d = e.second;
  10.         st.erase(st.begin());
  11.         for (auto u : g[v]) {
  12.             int to = u.first, w = u.second;
  13.             if (dist[to] > dist[v] + w) {
  14.                 st.erase({dist[to], to});
  15.                 dist[to] = dist[v] + w;
  16.                 st.insert({dist[to}, to});
  17.             }
  18.         }
  19.     }
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement