Advertisement
Guest User

Untitled

a guest
Apr 26th, 2015
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.78 KB | None | 0 0
  1.         int s = 0;
  2.         const int INF = 1000000000;
  3.     vector<long long> d (n+1, INF);
  4.         vector<int> p (n+1);
  5.         vector<bool> visited(n+1, false);
  6.     d[s] = 0;
  7.     priority_queue < pair<int,int> > q;
  8.     q.push (make_pair (0, s));
  9.     while (!q.empty()) {
  10.         int v = q.top().second,  cur_d = -q.top().first;
  11.             visited[v] = true;
  12.         q.pop();
  13.         if (cur_d > d[v])  continue;
  14.         for (size_t j=0; j<graph[v].size(); ++j) {
  15.             int to = graph[v][j].first;
  16.                     if (visited[to] != true) {
  17.                         visited[to] = true;
  18.                         int len = graph[v][j].second;
  19.                         if (d[v] + len < d[to]) {
  20.                                 d[to] = d[v] + len;
  21.                                 p[to] = v;
  22.                                 q.push (make_pair (-d[to], to));
  23.                         }
  24.             }
  25.         }
  26.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement