Advertisement
Nusrat_Ullah

Dijkstra

Nov 5th, 2020
1,883
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.54 KB | None | 0 0
  1. void dijkstra()
  2. {
  3.     int a,b,g;
  4.     ii f,m;
  5.     priority_queue<ii,vii,greater<ii>>pq;        //ii = pair<int,int>
  6.     pq.push(ii(0,s));
  7.     while(!pq.empty()){
  8.         f=pq.top(), pq.pop();
  9.         a=f.first, b=f.second;
  10.         if(a>dis[b])continue;
  11.         for(g=0;g<wq_list[b].size();g++){            //wq_list = adjacency list
  12.             m=wq_list[b][g];
  13.             if(dis[b]+m.second<dis[m.first]){
  14.                 dis[m.first]=dis[b]+m.second;
  15.                 pq.push(ii(dis[m.first],m.first));
  16.             }
  17.         }
  18.     }
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement